When getting a list of resources (for example GET /company/quotes), you can specify the query parameter filter to filter the results to retrieve. The format of the parameter filter is the same as MongoDB find queries.
Example : To find all the bills of a given client id, and in the month of May 2023, the query string will be
filter={"clientId":"123465789","creationDate":{"$between":["2023-05-01", "2023-05-31"]}}
Several operators are available to filter output :
-
The equality operator : To check the equality of a field, write :
{"fielname":"value"} -
The binary operators : The syntax of these operators is :
{"fieldname" : {"$operator" : "value"}}. The available logical operators are :- $ne : Not equal
- $lt : Lower than
- $lte : Lower than or equal
- $gt : Greater than
- $gte : Greater than or equal
- $like : Matches a given string pattern, in the SQL format
- $nlike : Does not match a given string pattern, in the SQL format
- $in : Match the field against a set of value -
{"fieldname" : {"$in" : ["value1", "Value2"]}} - $nin : Does not match the field against a set of value -
{"fieldname" : {"$nin" : ["value1", "Value2"]}} - $between : The field value is between two values (used for dates)-
{"fieldname" : {"$between" : ["2023-01-01", "2023-12-31"]}} - $notbetween : The field value is NOT between two values (used for dates)-
{"fieldname" : {"$notbetween" : ["2023-01-01", "2023-12-31"]}}
-
The unary operators: : The syntax of these operators is :
{"fieldname" : "$operator"}. There are actually two unary operators :$null: The value is null$notnull: The value is not null
-
The logical operators AND & OR : The syntax is
{"$or" : [{condition1, {condition2}]}For example :
{"$or" : [{"fieldname" : "value"}, {"fieldname" : "$null"}]}