$eq

The `$eq` operator is used to match documents where the value of a field is equal to a specified value.

Syntax

{ field: { $eq: <value> } }

Parameters

fieldstringrequired

The field to be compared

valuestringrequired

The value to compare against

Examples

Use $eq filter on a root level field

To find a store with a specific name, run a query with the $eq predicate to match on the name field.

Query:

db.stores.find({
    name: { $eq: "Boulder Innovations | Home Security Place - Ankundingburgh" }
}, { name: 1 })

Output:

[{ "_id": "bda56164-954d-4f47-a230-ecf64b317b43", "name": "Boulder Innovations | Home Security Place - Ankundingburgh" }]

Use $eq filter on a nested field

To find a store with total sales of exactly $37,015, run a query using the $eq operator using dot notation on the nested sales.totalSales field.

Query:

db.stores.find({
    "sales.totalSales": { $eq: 37015 }
}, { name: 1, "sales.totalSales": 1 })

Output:

[{ "_id": "bda56164-954d-4f47-a230-ecf64b317b43", "name": "Boulder Innovations | Home Security Place - Ankundingburgh", "sales": { "totalSales": 37015 } }]

Related