Search.../

queryLocations( )

Developer Preview

Creates a query to retrieve a list of locations.

Description

The queryLocations() function builds a query to retrieve a list of up to 1,000 locations and returns a LocationsQueryBuilder object.

The returned object contains the query definition which is typically used to run the query using the find() function.

You can refine the query by chaining LocationsQueryBuilder functions onto the query. LocationsQueryBuilder functions enable you to sort, filter, and control the results that queryLocations() returns. The functions that are chained to queryLocations() are applied in the order they are called.

queryLocations() runs with the following LocationsQueryBuilder defaults that you can override:

  • skip: 0
  • limit: 50

The following QueryLocationsBuilder functions are supported for the queryLocations() function. For a full description of the Locations object, see the object returned for the items property in LocationsQueryResult.

PROPERTYSUPPORTED FILTERS & SORTING
_ideq(),ne(),exists(),in(),hasSome(),startsWith()
nameeq(),ne(),exists(),in(),hasSome(),startsWith()
descriptioneq(),ne(),exists(),in(),hasSome(),startsWith()
defaulteq(),ne(),exists(),in(),hasSome()
statuseq(),ne(),exists(),in(),hasSome()
locationTypeeq(),ne(),exists(),in(),hasSome()
faxeq(),ne(),exists(),in(),hasSome(),startsWith()
timeZoneeq(),ne(),exists(),in(),hasSome(),startsWith()
emaileq(),ne(),exists(),in(),hasSome(),startsWith()
phoneeq(),ne(),exists(),in(),hasSome(),startsWith()
address.countryeq(),ne(),exists(),in(),hasSome(),startsWith()
address.subdivisioneq(),ne(),exists(),in(),hasSome(),startsWith()
address.cityeq(),ne(),exists(),in(),hasSome(),startsWith()
address.postalCodeeq(),ne(),exists(),in(),hasSome(),startsWith()
address.streetAddress.numbereq(),ne(),exists(),in(),hasSome(),startsWith()
address.streetAddress.nameeq(),ne(),exists(),in(),hasSome(),startsWith()
address.streetAddress.apteq(),ne(),exists(),in(),hasSome(),startsWith()
address.formattedAddresseq(),ne(),exists(),in(),hasSome(),startsWith()
address.hinteq(),ne(),exists(),in(),hasSome(),startsWith()
address.geocode.latitudeeq(),ne(),exists(),in(),hasSome(),lt(),le(),gt(),ge()
address.geocode.longitudeeq(),ne(),exists(),in(),hasSome(),lt(),le(),gt(),ge()
businessSchedule.periods.openDayeq(),ne(),exists(),in(),hasSome()
businessSchedule.periods.openTimeeq(),ne(),exists(),in(),hasSome(),startsWith()
businessSchedule.periods.closeDayeq(),ne(),exists(),in(),hasSome()
businessSchedule.periods.closeTimeeq(),ne(),exists(),in(),hasSome(),startsWith()
businessSchedule.specialHourPeriod.startDateeq(),ne(),exists(),in(),hasSome(),startsWith()
businessSchedule.specialHourPeriod.endDateeq(),ne(),exists(),in(),hasSome(),startsWith()
businessSchedule.specialHourPeriod.isClosedeq(),ne(),exists(),in(),hasSome()
businessSchedule.specialHourPeriod.commenteq(),ne(),exists(),in(),hasSome(),startsWith()
revisioneq(),ne(),exists(),in(),hasSome(),lt(),le(),gt(),ge()
archivedeq(),ne(),exists(),in(),hasSome()
Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function queryLocations(): LocationsQueryBuilder

queryLocations Parameters

This function does not take any parameters.

Returns

Was this helpful?

Retrieve all locations (dashboard page code)

Copy Code
1import { locations } from 'wix-business-tools.v2';
2import { elevate } from 'wix-auth';
3
4export async function myQueryLocationsFunction() {
5 try {
6 const elevatedQueryLocations = elevate(locations.queryLocations);
7 const myLocations = await elevatedQueryLocations().find();
8 const items = myLocations.items;
9 console.log('Locations:', items);
10
11 return items;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16}
17
18/* Returns items:
19 * [
20 * {
21 * "_id": "5c6e81a4-5270-4f66-9688-49d1fd9153ef",
22 * "address": {
23 * "city": "Amsterdam",
24 * "country": "NL",
25 * "formatted": "CityHub, Bellamystraat, Amsterdam, Netherlands",
26 * "location": {
27 * "latitude": 52.3672879,
28 * "longitude": 4.867098899999998
29 * },
30 * "postalCode": "1053 BE",
31 * "streetAddress": {
32 * "apt": "",
33 * "name": "Bellamystraat",
34 * "number": "3"
35 * },
36 * "subdivision": "NH"
37 * },
38 * "archived": false,
39 * "businessSchedule": {
40 * "periods": [],
41 * "specialHourPeriod": []
42 * },
43 * "default": false,
44 * "email": "amsterdam.store@example.com",
45 * "fax": "+31 20 765 4321",
46 * "name": "Bellamystraat",
47 * "phone": "+31 20 123 4567",
48 * "status": "ACTIVE",
49 * "timeZone": "Europe/Amsterdam",
50 * "revision": "1"
51 * },
52 * {
53 * "_id": "e3b2c1ff-2bf2-41da-9f4a-983c8799074a",
54 * "address": {
55 * "city": "Brisbane City",
56 * "country": "AU",
57 * "formatted": "Arise, Margaret Street, Brisbane City QLD, Australia",
58 * "location": {
59 * "latitude": -27.4718535,
60 * "longitude": 153.0288312
61 * },
62 * "postalCode": "4000",
63 * "streetAddress": {
64 * "apt": "",
65 * "name": "Margaret Street",
66 * "number": "222"
67 * },
68 * "subdivision": "QLD"
69 * },
70 * "archived": false,
71 * "businessSchedule": {
72 * "periods": [],
73 * "specialHourPeriod": []
74 * },
75 * "default": false,
76 * "email": "australia.store@examp;e.com",
77 * "fax": "+61 2 9876 5432",
78 * "name": "Margaret Street",
79 * "phone": "+61 2 1234 5678",
80 * "revision": "1",
81 * "status": "ACTIVE",
82 * "timeZone": "Australia/Brisbane"
83 * }
84 * ]
85 */
86
Retrieve all locations (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { locations } from 'wix-business-tools.v2';
3import { elevate } from 'wix-auth';
4
5export const myQueryLocationsFunction = webMethod(Permissions.Anyone, async () => {
6 try {
7 const elevatedQueryLocations = elevate(locations.queryLocations);
8 const myLocations = await elevatedQueryLocations().find();
9 const items = myLocations.items;
10 console.log('Locations:', items);
11
12 return items;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/* Returns items:
20 * [
21 * {
22 * "_id": "5c6e81a4-5270-4f66-9688-49d1fd9153ef",
23 * "address": {
24 * "city": "Amsterdam",
25 * "country": "NL",
26 * "formatted": "CityHub, Bellamystraat, Amsterdam, Netherlands",
27 * "location": {
28 * "latitude": 52.3672879,
29 * "longitude": 4.867098899999998
30 * },
31 * "postalCode": "1053 BE",
32 * "streetAddress": {
33 * "apt": "",
34 * "name": "Bellamystraat",
35 * "number": "3"
36 * },
37 * "subdivision": "NH"
38 * },
39 * "archived": false,
40 * "businessSchedule": {
41 * "periods": [],
42 * "specialHourPeriod": []
43 * },
44 * "default": false,
45 * "email": "amsterdam.store@example.com",
46 * "fax": "+31 20 765 4321",
47 * "name": "Bellamystraat",
48 * "phone": "+31 20 123 4567",
49 * "status": "ACTIVE",
50 * "timeZone": "Europe/Amsterdam",
51 * "revision": "1"
52 * },
53 * {
54 * "_id": "e3b2c1ff-2bf2-41da-9f4a-983c8799074a",
55 * "address": {
56 * "city": "Brisbane City",
57 * "country": "AU",
58 * "formatted": "Arise, Margaret Street, Brisbane City QLD, Australia",
59 * "location": {
60 * "latitude": -27.4718535,
61 * "longitude": 153.0288312
62 * },
63 * "postalCode": "4000",
64 * "streetAddress": {
65 * "apt": "",
66 * "name": "Margaret Street",
67 * "number": "222"
68 * },
69 * "subdivision": "QLD"
70 * },
71 * "archived": false,
72 * "businessSchedule": {
73 * "periods": [],
74 * "specialHourPeriod": []
75 * },
76 * "default": false,
77 * "email": "australia.store@examp;e.com",
78 * "fax": "+61 2 9876 5432",
79 * "name": "Margaret Street",
80 * "phone": "+61 2 1234 5678",
81 * "revision": "1",
82 * "status": "ACTIVE",
83 * "timeZone": "Australia/Brisbane"
84 * }
85 * ]
86 */
87
Retrieve locations using multiple filters

This is an example of a page where user searches for locations, and the search results populates a dropdown. The query only returns active locations.

Copy Code
1/****************************************
2 * Backend code - query-location.web.js *
3 ***************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { locations } from 'wix-business-tools.v2';
7import { elevate } from 'wix-auth';
8
9export const queryLocationsByNameStart = webMethod(Permissions.Anyone, async (searchInput) => {
10 try {
11 const elevatedQueryLocations = elevate(locations.queryLocations)
12 const result = await elevatedQueryLocations()
13 .startsWith('name', searchInput)
14 .eq('status', 'ACTIVE')
15 .find();
16
17 return result.items;
18 } catch (error) {
19 console.error(error);
20 throw new Error(error);
21 }
22});
23
24
25/*************
26 * Page code *
27 ************/
28
29import { queryLocationsByNameStart } from 'backend/query-location.web';
30
31$w.onReady(() => {
32 $w('#getBranchLocations').onClick(async () => {
33 const searchName = $w('#search').value;
34 const locations = await queryLocationsByNameStart(searchName);
35
36 const dropdownOptions = locations.map((location) => {
37 return {
38 label: location.name,
39 value: location._id
40 }
41 });
42 $w('#locationsDropdown').options = dropdownOptions;
43 });
44});
45