Query and Projection Operators (original) (raw)

Note

For details on a specific operator, including syntax and examples, click on the link to the operator's reference page.

You can use query and projection operators for deployments hosted in the following environments:

For comparison of different BSON type values, see the specified BSON comparison order.

Name Description
$eq Matches values that are equal to a specified value.
$gt Matches values that are greater than a specified value.
$gte Matches values that are greater than or equal to a specified value.
$in Matches any of the values specified in an array.
$lt Matches values that are less than a specified value.
$lte Matches values that are less than or equal to a specified value.
$ne Matches all values that are not equal to a specified value.
$nin Matches none of the values specified in an array.
Name Description
$and Joins query clauses with a logical AND returns all documents that match the conditions of both clauses.
$not Inverts the effect of a query predicate and returns documents that do not match the query predicate.
$nor Joins query clauses with a logical NOR returns all documents that fail to match both clauses.
$or Joins query clauses with a logical OR returns all documents that match the conditions of either clause.
Name Description
$exists Matches documents that have the specified field.
$type Selects documents if a field is of the specified type.
Name Description
$expr Allows use of aggregation expressions within the query language.
$jsonSchema Validate documents against the given JSON Schema.
$mod Performs a modulo operation on the value of a field and selects documents with a specified result.
$regex Selects documents where values match a specified regular expression.
$text Performs text search.$text provides text query capabilities for self-managed (non-Atlas) deployments. For data hosted on MongoDB Atlas, MongoDB offers an improved full-text query solution, Atlas Search.
$where Matches documents that satisfy a JavaScript expression.
Name Description
$all Matches arrays that contain all elements specified in the query.
$elemMatch Selects documents if element in the array field matches all the specified $elemMatch conditions.
$size Selects documents if the array field is a specified size.
Name Description
$bitsAllClear Matches numeric or binary values in which a set of bit positions all have a value of 0.
$bitsAllSet Matches numeric or binary values in which a set of bit positions all have a value of 1.
$bitsAnyClear Matches numeric or binary values in which any bit from a set of bit positions has a value of 0.
$bitsAnySet Matches numeric or binary values in which any bit from a set of bit positions has a value of 1.
Name Description
$ Projects the first element in an array that matches the query condition.
$elemMatch Projects the first element in an array that matches the specified $elemMatch condition.
$meta Projects the document's score assigned during the textoperation.textoperation.textoperation.text provides text query capabilities for self-managed (non-Atlas) deployments. For data hosted on MongoDB Atlas, MongoDB offers an improved full-text query solution, Atlas Search.
$slice Limits the number of elements projected from an array. Supports skip and limit slices.
Name Description
$rand Generates a random float between 0 and 1.
$natural A special hint that can be provided via thesort() or hint() methods that can be used to force either a forward or reverse collection scan.