> For the complete documentation index, see [llms.txt](https://docs.medable.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.medable.com/cortex-api/querying/query-operators.md).

# Query Operators

Query operators can be used to construct query conditions in order to find data. Query operators are typically applied to a property and take a value or a document defining the conditions of the operation.

For example:

```
{<property>: {<operator>: value}}
```

Or:

```
{<property>: {<operator>: {<option>: <value>, <option>: value, ...}}}
```

Or, in the case of logical operators (e.g. `$and`, `$or`), the operator takes an array of expressions:

```
{<operator>: [{<expression>}, {<expression>}, ...]}
```

### Usage

Query operators can be used in a `where` query argument or in a `$match` pipeline stage .

When used in a `where` query argument, the request looks similar to the following:

```
GET /<object>?where={<query conditions>}
```

When used in a `$match` pipeline stage, the request looks similar to the following:

```
GET /<object>?pipeline=[{"$match":{<query conditions>}}]
```

### Query Operator Types

| Type                 | Description                                                             |
| -------------------- | ----------------------------------------------------------------------- |
| Comparison Operators | For filtering results based on value comparisons.                       |
| Logical Operators    | Join query clauses together or invert the meaning of a query expression |
| Evaluation Operators | Filter results based on the result of a regular expression              |
| Geospatial Operators | Find locations within a distance of a central location.                 |
| Array Operators      | Match on arrays, elements in an array, or size of arrays.               |

### Comparison Operators

| Operator | Description                                                                                        | Example                                         |
| -------- | -------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| $eq      | Selects documents where the value of the property is equal to the passed in value.                 | {“c\_bpm”: {“$eq”: 70}}                         |
| $gt      | Selects documents where the value of the property is greater than the passed in value.             | {“c\_bpm”: {“$gt”: 70}}                         |
| $gte     | Selects documents where the value of the property is greater than or equal to the passed in value. | {“c\_bpm”: {“$gte”: 70}}                        |
| $lt      | Selects documents where the value of the property is lesser than the passed in value.              | {“c\_bpm”: {“$lt”: 70}}                         |
| $lte     | Selects documents where the value of the property is lesser than or equal to the passed in value.  | {“c\_bpm”: {“$lte”: 70}}                        |
| $ne      | Selects documents where the value of the property is not equal to the passed in value.             | {“c\_bpm”: {“$ne”: 70}}                         |
| $in      | Selects documents where the property matches **any** of the passed in values.                      | {“c\_bpm”: {“$in”: \[65, 66, 67, 68, 69, 70]}}  |
| $nin     | Selects documents where the property matches **none** of the passed in values.                     | {“c\_bpm”: {“$nin”: \[65, 66, 67, 68, 69, 70]}} |

### Logical Operators

| Operator | Description                                                         | Example                                                          |
| -------- | ------------------------------------------------------------------- | ---------------------------------------------------------------- |
| $and     | Selects documents where all passed in conditions are met.           | {“$and”: \[{“c\_bpm”: {“$gt”: 70}}, {“c\_bpm”: {“$lt”: 100}}] }  |
| $or      | Selects documents where any passed in conditions are met.           | {“$or”: \[{“c\_bpm”: {“$gt”: 70}}, {“c\_bmi”: {“$gt”: 24.9}}] }  |
| $not     | Evaluates to true if the property or expression evaluates to false. | {“$not”: “c\_active”}                                            |
| $nor     | Selects documents where none of the passed in conditions are met.   | {“$nor”: \[{“c\_bpm”: {“$gt”: 70}}, {“c\_bmi”: {“$gt”: 24.9}}] } |

### Evaluation Operators

| Operator | Description                                                                           | Example                                      |
| -------- | ------------------------------------------------------------------------------------- | -------------------------------------------- |
| $regex   | Selects documents where the string property matches the passed in regular expression. | {“name.first”: {“$regex”: “/^samplename/i”}} |

### Geospatial Operators

| Operator | Description                                                                           | Example                                                                             |
| -------- | ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| $within  | Selects documents with geospatial data that exists entirely within a specified shape. | {"c\_location": {"$within": {"$center": \[-122.143019, 37.441883], "$radius": 10}}} |

### Array Operators

| Operator   | Description                                                                                                                                                                                                              | Example                                                                        |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
| $all       | Selects documents where the array property contains all of the passed in values.                                                                                                                                         | {“roles”: {“$all”: \[“000000000000000000000007”, “0123456789ab0123456789ab”]}} |
| $elemMatch | Selects documents where all properties of an array of document properties match the passed in expression. $elemMatch does not limit the results within the array, but filters the entire document for contained entries. | {“c\_docs”: {“$elemMatch”: {“c\_foo”: “yes”, “c\_bar”: true}}}                 |
| $size      | Selects documents where the size of the array property matches the passed in values.                                                                                                                                     | {“c\_arr”: {“$size”: 20}}                                                      |
