Search code examples
mongodbreplicationmongodb-replica-set

Where are mongo replication settings stored?


After a complete reinstall of mongo, it has still remembered the replica set configuration from before; where has it stored this?

I installed mongo on a linux server, using our project's user account, into a directory owned by that user. I set up replication and had it working fine. Then, to test out some finer install points, I removed the whole mongo directory and did a reinstall. Entering into mongo, I found that the replication was already set up as before; so it would appear that mongo is storing the information somewhere.

I have checked several areas which might have been holding the replica set config:

  1. First, in the mongo directory, but that was deleted.
  2. In some traditional linux structure probably owned by root, but the project user does not have root access and mongo, run by the same, should not either.
  3. The project user's home directory. Now this does have a .dbshell file containing the command line history, but only that. I did not see any other files there that related.
  4. Some location specified in the mongo configuration. But I only have two paths mentioned in there, one for the system log (systemLog.path) and the other for storage (storage.dbPath), and the both point to the mongo directory, which was deleted.

Does anyone know where mongo is storing this configuration information?


Solution

  • The replication data is stored in the local database in each node (as of MongoDB 3.2.9). This database contains information about the replica set, and also contains the oplog (the oplog.rs collection). The replica set information is stored in the system.replset collection in this local database.

    The physical files for this database (and also for other databases) are stored in the dbPath directory, which can be configured using:

    • The --dbpath parameter when starting mongod
    • The storage.dbPath setting in the configuration file

    The default dbpath value is /data/db

    Your replica set setting will not be retained if you emptied the dbpath directory. If you find that the replication settings are being retained, it is possible that the dbpath setting is incorrect.