findOneAndUpdate
findOneAndUpdate changes a document and returns it in one atomic step. Use it for counters and queues.
Example
db.jobs.findOneAndUpdate(
{ status: "new" },
{ $set: { status: "working" } },
{ returnDocument: "after", sort: { created: 1 } }
)Exercise
Return the new version.
returnDocument: ""
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.