Definition
$eqCompares two values and returns:
truewhen the values are equivalent.falsewhen the values are not equivalent.
The
$eqcompares both value and type, using the specified BSON comparison order for values of different types.$eqhas this syntax:{ $eq: [ <expression1>, <expression2> ] } The arguments can be any valid expression. For more information on expressions, see Expressions.
Example
The following example uses the movies collection from the sample_mflix
sample dataset. For details on how to load this dataset into your deployment, see Load the sample dataset.
This aggregation operation uses the $eq operator to determine if the year field equals 1978:
db.movies.aggregate( [ { $match: { runtime: { $gt: 1000 } } }, { $project: { _id: 0, title: 1, year: 1, yearEq1978: { $eq: [ "$year", 1978 ] } } } ] )
[ { title: 'Centennial', year: 1978, yearEq1978: true }, { title: 'Baseball', year: 1994, yearEq1978: false } ]