I have the following docker-compose file that starts my MongoDB as standalone (in PROD).
version: '3.1' services: mongo: image: mongo restart: always # entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ] ports: - 27017:27017 # admin environment: MONGO_INITDB_ROOT_USERNAME: admin MONGO_INITDB_ROOT_PASSWORD: superlongpassword volumes: - /host/mongodb:/data/db
My goal: convert this instance to the PRIMARY in a replica set.
I have another instance running, freshly set up, currently doing nothing (if this works, I’ll add a 3rd).
My thinking was that, stopping the instance, uncommenting the ‘entrypoint’ line and bringing the instance back up, would convert the standalone instance into a replica set instance, as described in this tutorial .
However, when doing this, I get:
(in mongosh): test> rs.initiate() MongoServerError: already initialized (PS: I had tried this before...) test> rs.status() MongoServerError: Our replica set config is invalid or we are not a member of it.
Any hints in what I’m doing wrong?