I am kind of late to the Mongo train, but we are now moving away from Postgres (Heroku) into Mongo (Atlas).
I find it surprising that findAndModify() only works on a single document. We have many nice use cases where we need to update multiple documents AND get their values (old values before the update) in one atomic operation. Just curious if there is any special reason why this hasn’t been implemented yet.
Is findAndModifyMany() something that is planned? Can we vote somewhere on this feature request?
New features should be suggested at feedback.mongodb.com - Jira is for bug reports for the most part.
I’m curious though why you specifically want findAndModify to take multiple updates/return multiple documents - why not findAndModify for each? Otherwise how do you sort out which returned document was for which findAndModify? Normally write operations return back a single result document, and only read operations return a cursor with multiple documents.
We have a collection where each document is a “bucket” of a specific time span, from which you can check if there are steps available. We want in an atomic, one call, to get stepsTotal and stepsConverted and set stepsConverted to be stepsTotal (because we’ve just “drunk” all the available steps from those documents). We also set the isHasAvailable to FALSE.
If you want multiple document writes to be atomic you can’t do it with update or any other write outside a transaction. Only single document writes are atomic. Sounds like you’ll need to use a transaction.