You have a MongoDB collection named employees that contains documents with fields name, department, and salary. You want to update the salary of all employees in the "Marketing" department to $75,000. The original collection looks like this:
What will the collection look like after this update operation?
Answer: C
Question 2
Which of the following statements correctly describes the relationship between BSON and JSON in MongoDB?
Answer: C
Question 3
Consider the following scenario: You have a MongoDB collection named users that stores user information. Each document in the collection has the following structure:
{
"_id": ObjectId("609fe4b5728ad805aef1a88d"),
"name": "John Doe",
"age": 30,
"email": "johndoe@example.com",
"address": {
"street": "123 Main St",
"city": "New York",
"state": "NY",
"zipcode": "10001"
}
}
You need to retrieve all the documents from the users collection and convert them to an array format. Which of the following MongoDB queries should you use for this task?
Answer: B
Question 4
What is the difference between a sparse index and a non-sparse index in MongoDB?
Answer: A
Question 5
Consider a tasks collection that holds task records. The document structure is as follows:
{
"_id": ObjectId("64b64c58ed01c0a5e72dbf5f"),
"task": "Review PR",
"status": "pending",
"assignedTo": "alice"
}
Two operations are performed concurrently:
Operation A:
db.tasks.findAndModify({
query: { task: "Review PR", status: "pending" },
remove: true
});
Operation B:
db.tasks.findAndModify({
query: { task: "Review PR", status: "pending" },
update: { $set: { status: "completed" } },
new: true
});
Operation B starts slightly after Operation A but before Operation A completes. What will be the final state of the tasks collection after both operations have been executed?