Filtering

Using the Javascript SDK is the easiest way to filter collections however, when choosing to filter a collection directly, you use the filters query parameter. The parameter value is a list of document.myProperty followed by the comparison operator (see the table below), then the value against with to compare.

For example, to filter a collection to only return documents where the value stored in myProperty is equal to test using CURL would look like:

curl \
    -X GET \
    -H "Content-Type: application/json" \
    --silent \
    -fS https://my-data-service.datastore.squiz.cloud/my-first-collection?filters=document.myProperty===test

Filtering with multiple properties at once is done using ; (and) and , (or) logic between the document properties in the query.

For example, to filter a collection to only return documents that contain the document property, myProperty equal to test and the document property myViews less than 10 or greater than 20 using CURL would look like:

curl \
    -X GET \
    -H "Content-Type: application/json" \
    --silent \
    -fS https://my-data-service.datastore.squiz.cloud/my-first-collection?filters=document.myProperty===test;document.myViews<10,document.myViews>20

Filter logic also allows for the grouping of conditions using brackets. Take the above example of filtering a collection to only return documents where the value stored in myProperty is equal to test and the document property myViews value is not between 10 and 20 using CURL would look like:

curl \
    -X GET \
    -H "Content-Type: application/json" \
    --silent \
    -fS https://my-data-service.datastore.squiz.cloud/my-first-collection?filters=document.myProperty===test;(document.myViews<10,document.myViews>20)

Filter comparison operators

Description Operator Compatible property types

Equals

===

Non-array properties

Does not equal

!==

Non-array properties

Greater than

>

Non-array properties

Less than

<

Non-array properties

Greater than or equal to

>=

Non-array properties

Less than or equal to

<=

Non-array properties

Contains

@>

Array properties

Does not contain

!@>

Array properties

Contains any

~@>

Array properties

Does not contain any

!~@>

Array properties