Running MongoDB in local environment using Docker without installing the MongoDB server would be my preference since I use Docker. The reason is obvious, I don’t want to clutter my development environment with a bunch of database server installations.
With Docker installed on development environment I could just simply execute the following command to spin up a new MongoDB server running in a container:
docker run -d -p 27017:27017 –name=local-mongodb mongo:3.6
But, still to connect with the database you would need a client, in my case, I simply installed the mongodb-org-shell and use it to connect to the MongoDB database running in the container. The earlier command I showed to you will run the MongoDB container and expose the 27017 port to the host machine. Connecting to the MongoDB in the container would simply just executing the following command on the CLI:
I use this approach in several projects, and I am quite happy.