1. Insert Multiple Documents

You have a users collection with fields: _id, name, email, age, address, and createdAt.

Question:

Write a query to insert the following users into the users collection:

[
  { "name": "Alice", "email": "[email protected]", "age": 25, "address": "New York", "createdAt": ISODate("2024-02-01T10:00:00Z") },
  { "name": "Bob", "email": "[email protected]", "age": 30, "address": "San Francisco", "createdAt": ISODate("2024-02-02T12:00:00Z") },
  { "name": "Charlie", "email": "[email protected]", "age": 35, "address": "Los Angeles", "createdAt": ISODate("2024-02-03T15:00:00Z") }
]


2. Find Users with Conditions

The users collection has an age field.

Question:

Write a query to find all users who are aged between 25 and 40, but exclude those from "San Francisco". The result should only include their name and email.


3. Update User's Email Based on a Condition

Question:

Update the email of the user whose name is "Alice" to "[email protected]", but only if they are below 30 years old.


4. Delete Users Created Before a Certain Date

Question:

Delete all users who were created before January 1, 2024.


5. Aggregation: Find Average Age by City