In MongoDB, you can use filters to specify the conditions that must be met for a document to be included in the result set. Filters can be used with the find()updateOne(), and deleteOne() methods.

Filter Syntax

Filters are specified using a JSON-like syntax:

{key: value}

For example

To filter documents where age is equal to 20, use:

{ age: 20 }

Or

{ key: { $Operators: value }}

For example

To filter documents where age is greater than 20, use:

{ age: { $gt: 20 }}

Operators

MongoDB provides several operators to specify filters, such as: