0

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?

  • 1
    According to mongo documentation you can not write to secondary nodes -> https://docs.mongodb.com/manual/core/replica-set-secondary - otherwise it would be master-master replication. Replication goes into one direction primary -> secondary – mkorszun Oct 07 '16 at 09:26

1 Answers1

1

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

JJussi
  • 1,540
  • 12
  • 12