Logical operators may be used to combine comparison operators to create compound searches.
$AND
- Available Since API Version – 2.4
The $AND operator combines one or more operands with a logical AND, meaning that all of the supplied operands must be true in order for a record to match the criteria. The $AND operator will accept an array containing any combination of comparison or logical operators as operands, including another $AND operator, thus allowing you to create complex nested conditional searches.
Examples
The example below illustrates how to use the $AND operator when constructing a search query.
$AND Example
The following is an example of an $AND search which would retrieve all address book entries whose Company Name begins with the letter "A" and who have the position of "President".
{
"$AND":[
{
"CompanyName":{
"$LIKE":"A%"
}
},
{
"Position":{
"$EQ":"President"
}
}
]
}
$OR
- Available Since API Version – 2.7
The $OR operator combines one or more operands with a logical OR, meaning that any records for which one or more of the supplied operands are true will match the criteria. The $OR operator will accept an array containing any combination of comparison or logical operators as operands, including another $OR operator, thus allowing you to create complex nested conditional searches.
Examples
The example below illustrates how to use the $AND operator when constructing a search query.
$OR Example
The following is an example of an $OR search which would return all entries whose Company Name begins with "ABC" or who have a last name of "Napoli".
{
"$OR":[
{
"CompanyName":{
"$LIKE":"ABC%"
}
},
{
"LastName":{
"$EQ":"Napoli"
}
}
]
}