Filtering Query Results
TinaCMS automatically creates filters for collections defined in your schema.
To filter collection results, pass the filter argument to the <collection>Connection query, followed by any of the filter operator types for the fields on your collection.
The filter object is a nested set of conditions where the keys correspond to the collection field and the value describes the condition.
Conditions can be either "binary" or "ternary". A binary condition is composed of a single operator and a single operand (i.e. {"eq":"foo"}). A ternary condition is composed of two operators and two operands (.i.e. {"gt":0, "lte": 10}).
Operator types
Equals
One of
Greater than
Greater than or equal to
Less than
Less than or equal to
Starts with
After
Before
Only
gt,gte,lt,lte,after,beforemay be used in ternary conditions.
Examples
Filtering on a field
Here we will query our post collection with postConnection and filter the results by the post title:
Filtering on a field with the IN operator
Here we will query our post collection with postConnection and filter the results so that only members of the specified category are returned:
Filtering on a date range
Here we will query our post collection with postConnection and filter the results so that only posts with a date between the specified range are returned:
Filtering on multiple fields
It is possible to filter on multiple fields. Multiple conditions are currently treated as a boolean AND operation. Here we will query our post collection with postConnection and filter the results by category and title:
Filtering on a reference
Here we will query our post collection with postConnection, and filtering on the referenced author's name: