For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

$eq (expression operator)

$eq

Compares two values and returns:

  • true when the values are equivalent.

  • false when the values are not equivalent.

The $eq compares both value and type, using the specified BSON comparison order for values of different types.

$eq has this syntax:

{ $eq: [ <expression1>, <expression2> ] }

The arguments can be any valid expression. For more information on expressions, see Expressions.

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
}
]
Rate this page

On this page