How to use MongoDB for local development?

Hey guys,

I want to use MongoDB in Docker for my local development and MongoDB Atlas for production. At this moment, MongoDB Atlas Free doesn’t provide a possibility to choose MongoDB 6.0.3 and locked to use 5.0.x.

As far as I understand, it is okay to use a MongoDB replica set with only one primary node for local development.

Is there any official guide that helps me to configure it with Docker?

Hello, @Roman_Mahotskyi , you can try to follow this : Docker & MongoDB | Containers & Compatibility | MongoDB

Hey @Alex_Maxime, I just realized that I didn’t mention transactions in my question. Do you know how to set-up Docker + MongoDB + transactions?

P.S. Some people on the internet are saying that MongoDB + Transactions can be used in a replica set with only the primary node? How can I do this?

Hi @Roman_Mahotskyi welcome to the community!

You can follow the instructions in Convert a Standalone to a Replica Set. Basically after executing rs.initiate(), you don’t add more nodes to the replica set. By default, it should progress as a single node replica set as PRIMARY.

As with using Docker, this seems to work for me:

docker run --name some-mongo -p 27017:27017 mongo --replSet rsname

You should be able to connect to your host’s port 27017 using mongosh, then execute rs.initiate() there.

Note that this is a very basic example, so its storage is managed by Docker. If your needs are more specific, please see more detailed examples in Docker

Having said that, please note that the Docker Hub’s official MongoDB image is not maintained by MongoDB. Rather, it’s maintained by Docker.

Best regards


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.