In MongoDB, operators are used to perform various operations in queries, updates, aggregations, and other operations.
These operators enable us to manipulate data in the database in various ways.
These operators compare values and return true or false.
$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.
$gte: Matches values that are greater than or equal to a specified value.
$lt: Matches values that are less than a specified value.
$lte: Matches values that are less than or equal to a specified value.
These operators perform logical operations on expressions.
$and: Joins query clauses with a logical AND and returns all documents that match the conditions of both clauses.
$or: Joins query clauses with a logical OR and returns all documents that match the conditions of either clause.
$not: Inverts the effect of a query expression and returns documents that do not match the query expression.
These operators test for the existence of fields or check their type.
$exists: Matches documents that contain the specified field.
$type: Selects documents if a field is of the specified type.
These operators perform operations on arrays.
$in: Matches any of the values specified in an array.
$nin: Matches none of the values specified in an array.
$all: Matches arrays that contain all elements specified in the query.
These operators modify the values of fields in documents.
$set: Sets the value of a field in a document.
$unset: Removes the specified field from a document.
$inc: Increments the value of a field by a specified amount.
$push: Adds an element to an array.
$addToSet: Adds elements to an array only if they do not already exist in the set.
These operators group documents by a specified expression.
$group: Groups documents by a specified expression and applies accumulator expressions to each group.
$sum, $avg, $min, $max: Accumulator expressions used within the `$group` stage.
These operators modify the presentation of documents in the output.
$project: Reshapes documents by including, excluding, or adding fields.
These operators perform operations on arrays during aggregation.
$unwind: Deconstructs an array field from the input documents to output a document for each element.