Search.../

or( )

Adds an or condition to the query or filter.

Description

The or() function adds an inclusive or condition to a WixDataQuery or WixDataFilter. A query or filter with an or returns all the items that match the query or filter as defined up to the or function, the items that match the query or filter passed to the or function, and the items that match both.

The collections used by both the initial query and the query passed to the or function must be the same.

The 'or()' function is designed to work with 2 or more queries or filters. If you use it on its own, it will return all the items in a collection.

Authorization

Request

This endpoint does not take any parameters

Response Object

A WixDataQuery object representing the refined query.

Returns an empty object.

Status/Error Codes

Was this helpful?

Add an or to a query

Copy Code
1let newQuery = query1.or(query2);
Create a query, add an or, and run it

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5wixData.query("myCollection")
6 .lt("age", 25)
7 .or(
8 wixData.query("myCollection")
9 .gt("age", 65)
10 )
11 .find()
12 .then((results) => {
13 if(results.items.length > 0) {
14 let items = results.items;
15 let firstItem = items[0];
16 let totalCount = results.totalCount;
17 let pageSize = results.pageSize;
18 let currentPage = results.currentPage;
19 let totalPages = results.totalPages;
20 let hasNext = results.hasNext();
21 let hasPrev = results.hasPrev();
22 let length = results.length;
23 let query = results.query;
24 } else {
25 // handle case where no matching items found
26 }
27 })
28 .catch((error) => {
29 let errorMsg = error.message;
30 let code = error.code;
31 });
32
33 /*
34 * For example, results contain items where age is:
35 * 18
36 * 21
37 * 67
38 * 90
39 *
40 * But not items where age is:
41 * 25
42 * 30
43 * 40
44 * 65
45 */