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.
Syntax
function or(query: WixDataQuery): WixDataQuery
or Parameters
NAME
TYPE
DESCRIPTION
Mixed in from:wix-data.WixDataFilter
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';23// ...45wixData.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 found26 }27 })28 .catch((error) => {29 let errorMsg = error.message;30 let code = error.code;31 });3233 /*34 * For example, results contain items where age is:35 * 1836 * 2137 * 6738 * 9039 *40 * But not items where age is:41 * 2542 * 3043 * 4044 * 6545 */