MongoDB Docker Container Initiate Replica Set Link to heading
When running MongoDB in Docker, a replica set needs to first be initialized for many features and clients to work.
docker exec -it myMongoContainer mongosh
# mongosh inside container:
rs.initiate({_id: 'rs0', members: [{_id: 0, host: 'localhost:27017'}]})
This can be done directly through docker exec
too:
docker exec myMongoContainer mongo --eval "rs.initiate({_id: 'rs0', members: [{_id: 0, host: 'localhost:27017'}]});"