Consider a MongoDB collection named products which has documents in the following format:
{
"_id" : ObjectId("5f5b0d2f3e3dfbcc11c84444"),
"name" : "Smartphone",
"brand" : "Apple",
"category" : "Electronics",
"price" : 1000,
"discount" : 0.1
}
What is the correct syntax to update the "price" field of all documents in the products collection by multiplying it with (1 - discount) using the $set operator and the $multiply operator?
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?