Search⌘ K
AI Features

Solution: Using Regular Expressions

The solution utilizes the find() method to query the customers collection, filtering for emails that end with @gmail.com using the $regex operator for case-insensitivity. It also identifies premium customers with an ordersCount of three or more using the $gte operator. The projection specifies the fields to return, including the customer's name, email, and ordersCount, while excluding the default _id field. Regular expressions and comparison operators are key concepts for filtering and retrieving specific data in MongoDB queries.

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 ...