loopbackio / loopback-connector-mongodb

The official MongoDB connector for the LoopBack framework.
https://loopback.io/doc/en/lb4/MongoDB-connector
Other
187 stars 236 forks source link

updateAttributes/upsert cause "MongoError: not master" when running with mongodb replica set #111

Closed makersu closed 7 years ago

makersu commented 9 years ago

UpdateAttributes/upsert will cause MongoError due to update to secondary?

error message:

{
  "error": {
    "name": "MongoError",
    "status": 500,
    "message": "not master",
    "note": "from execCommand",
    "ok": 0,
    "errmsg": "not master",
    "stack": "Error\n    at Error.MongoError (/var/lib/strong-pm/.strong-pm/work/666d9c899a7906af6da8589826205806b69c4e9d.1426047850807/node_modules/loopback-connector-mongodb/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:13:17)\n    at Function.MongoError.create (/var/lib/strong-pm/.strong-pm/work/666d9c899a7906af6da8589826205806b69c4e9d.1426047850807/node_modules/loopback-connector-mongodb/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11)\n    at /var/lib/strong-pm/.strong-pm/work/666d9c899a7906af6da8589826205806b69c4e9d.1426047850807/node_modules/loopback-connector-mongodb/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:768:66\n    at Callbacks.emit (/var/lib/strong-pm/.strong-pm/work/666d9c899a7906af6da8589826205806b69c4e9d.1426047850807/node_modules/loopback-connector-mongodb/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:84:3)\n    at null.messageHandler (/var/lib/strong-pm/.strong-pm/work/666d9c899a7906af6da8589826205806b69c4e9d.1426047850807/node_modules/loopback-connector-mongodb/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:218:23)\n    at Socket.<anonymous> (/var/lib/strong-pm/.strong-pm/work/666d9c899a7906af6da8589826205806b69c4e9d.1426047850807/node_modules/loopback-connector-mongodb/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:256:22)\n    at Socket.emit (events.js:95:17)\n    at Socket.<anonymous> (_stream_readable.js:764:14)\n    at Socket.emit (events.js:92:17)\n    at emitReadable_ (_stream_readable.js:426:10)"
  }
}

datasources.json:

{
  "db": {
    "url":"mongodb://192.168.4.41,192.168.4.42,192.168.4.43/nucloud?readPreference=secondaryPreferred",
    "connector": "mongodb"
  }
}

numessage.js

...
Numessage.findOne(
        {
                where: {
                url: data.url
                }
        },
        function(err,numessageInstance) {

                if(numessageInstance && numessageInstance.id){
                        numessageInstance.updateAttributes(data, function(err,obj){
                                if(err){
                                        console.log(err)
                                }
                                cb(err, obj);
                                });
                }
makersu commented 9 years ago

My solution: use updateAll instead.

Numessage.updateAll({_id:numessageInstance.id},data, function(err,obj){
                        if(err){
                            console.log(err)
                        }
                        console.log(obj)
                        cb(err, obj);
                    });
wrensburg commented 9 years ago

Ditto here! Any progress yet?

vasiliyb commented 9 years ago

Folks, we are seeing this with MongoDB v 2.6.9, nodejs driver 1.4.38. Any solutions? Found similar posts: http://stackoverflow.com/questions/26405536/mongo-mongoid-exception-failed-with-error-not-master

MrMMorris commented 9 years ago

I am also seeing the not master error with mongo 3.0.3 and connector 1.8.0:

{
  "error": {
    "name": "MongoError",
    "status": 500,
    "message": "not master",
    "note": "from execCommand",
    "ok": 0,
    "errmsg": "not master"
  }
}

datasources.json:

options: {
      readPreference: 'secondaryPreferred',
      replicaSet: 'replica-1',
    },
pxwise commented 8 years ago

+1 Any update?

dharmendrasdlt commented 7 years ago

@MrMMorris Will this work ? Will this actually use replicaset ? I see no way in the connector files where replicaSet is used. https://github.com/strongloop/loopback-connector-mongodb

stale[bot] commented 7 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 7 years ago

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.