Version: Next
Queries
The DataStore Models provides two functions for executing queries.
#
query()Here we can fetch all documents for a Model or a selection of the documents using filters.
In the code snippet above, we fetch all tasks. To fetch a selection of the documents we can use filters. We filter using expressions and operators.
#
OperatorsAll supported operators:
Operator | Value |
---|---|
ne | Input not equal to value |
eq | Input equal to value |
le | Input less than or equal to value |
lt | Input less than (strict) value |
ge | Input greater than or equal to value |
gt | Input greater than (strict) value |
in | Input array or string contained in value |
contains | Value starts with input |
startsWith | Value starts with input |
endsWith | Value ends with input |
#
Operator support:Operator | Mathematical | String | Date | Array | Boolean |
---|---|---|---|---|---|
ne | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
eq | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
le | ✔️ | ✔️ | ✔️ | ✖️ | ✖️ |
lt | ✔️ | ✔️ | ✔️ | ✖️ | ✖️ |
ge | ✔️ | ✔️ | ✔️ | ✖️ | ✖️ |
gt | ✔️ | ✔️ | ✔️ | ✖️ | ✖️ |
in | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
contains | ✖️ | ✔️ | ✖️ | ✔️ | ✖️ |
startsWith | ✖️ | ✔️ | ✖️ | ✔️ | ✖️ |
endsWith | ✖️ | ✔️ | ✖️ | ✔️ | ✖️ |
#
Examples:You can also create expressions with the following logical operators:
- AND
- OR
- NOT
#
queryById()Here we fetch documents using their primary key. Quering by Id is faster because DataStore index documents by their primary key.