Query Operators:

MongoDB Query Operators are special symbols or keywords used in queries to perform various operations on documents in a MongoDB collection. These operators enable you to construct complex and precise queries to retrieve or manipulate data. Here are some commonly used MongoDB query operators:



Comparison Operators:

$eq: Matches values that are equal to a specified value.

$ne: Matches values that are not equal to a specified value.

$gt: Matches values that are greater than a specified value.

$lt: Matches values that are less than a specified value.

$gte: Matches values that are greater than or equal to a specified value.

$lte: Matches values that are less than or equal to a specified value.

$in: Matches any of the specified values.

$nin: Matches none of the specified values.

Logical Operators:

$and: Joins query clauses with a logical AND.

$or: Joins query clauses with a logical OR.

$not: Inverts the effect of a query expression.

$nor: Joins query clauses with a logical NOR.

Element Operators:

$exists: Matches documents that have a specified field.

$type: Matches documents based on the BSON type of a field.

Array Operators:

$elemMatch: Matches documents that contain an array element satisfying all the specified criteria.

$size: Matches documents where the size of a specified array field matches a specified value.

Evaluation Operators:

$expr: Allows the use of aggregation expressions within the query language.

$regex: Matches documents based on a specified regular expression pattern.

$text: Performs text search on string fields.

$mod: Matches documents where a field's value is divisible by a specified divisor.

Geospatial Operators:


$geoWithin: Matches documents that are within a specified geometry.

$geoIntersects: Matches documents that intersect a specified geometry.

$near: Returns documents near a specified location.

$nearSphere: Returns documents near a specified location on a sphere.

These are just a few examples of MongoDB query operators. MongoDB provides a wide range of operators to handle various querying and manipulation requirements. You can combine these operators and use them in different contexts to create powerful and flexible queries in MongoDB. For more details, refer to the MongoDB documentation on query operators.