Search⌘ K
AI Features

Solution: Using Regular Expressions

We'll cover the following...
Query
db.customers.find(
{
email: { $regex: /@gmail\.com$/i },
ordersCount: { $gte: 3 }
},
{
name: 1,
email: 1,
ordersCount: 1,
_id: 0
}
)

Explanation

The explanation of the query is given below:

  • Line 1: Start querying the customers collection using the find() method.

  • Line 3: This filter selects customers whose email ends with @gmail.com. The $regex operator matches text patterns using regular expressions. The pattern ...