Search code examples
mongodbmongodb-replica-set

Mongo replication issue in system.user database


I am able to add a user to systems.users collection when I register from primary node, But when I add a user from secondary node, value is not getting updated in the primary and so the replication fails, primary is in US and secondary is in Europe.


    var user = {
            user: email,
            pwd: password,
            roles: [
                {
                    role: "readWrite",
                    db: "newUser"
                }
            ]
        };
    db.addUser(user);
    res.send('added');

Am I missing anything?


Solution

  • As mkorszun wrote, every write operation MUST be done at primary. You can of course read from secondary, if you set slaveOk=true.