Defining a query filter

The filter (https://docs.mongodb.com/manual/tutorial/query-documents/) is a JSON expression, which defines criteria by which documents are either included in or excluded from the final result set. The filter usually consists of two elements, a document field name and an expression. The expression can be a hard-coded value, a regular expression (https://en.wikipedia.org/wiki/Regular_expression), or a statement that involves one or more query selectors (https://docs.mongodb.com/manual/reference/operator/query/#query-selectors) (or operators). 

A brief list of built-in query selectors is shown here:

Operator Meaning Operator Meaning
$eq equal to $and logical AND
$ne not equal to $or logical OR
$lt less than

Get MongoDB 4 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.