As suggested in accepted answer, you need to have your local server to be run as a replica set to be able to perform transactions, as opposed to standalone server.
However, in addition to the proposed solution, you can easily convert your Standalone local db to a Replica Set without using any third-party tool, by following instructions in MongoDB documentation, summarized as follows:
- Stop your standalone mongod instance, and restart it with the
replSetargument.
mongod --port 27017 --dbpath /srv/mongodb/db0 --replSet rs0 --bind_ip localhost
- Connect to your instance with a
mongoshell, and initiate the new Replica Set.
rs.initiate()
Now you should have a Replica Set instead of a Standalone mongodb server, where you can perform transactions on your local environment to update multiple documents at once!
Do not forget to include the replSet argument every time you want to start the server, otherwise it will be started as Standalone. I simply use the same command as in step 1 to run it again.
Alternatively, you can deploy a new Replica Set from scratch for testing environment following these other instructions in MongoDB documentation.