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") }
]
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.
Question:
Update the email of the user whose name is "Alice" to "[email protected]", but only if they are below 30 years old.
Question:
Delete all users who were created before January 1, 2024.