strange mongodb and mongoose error: not master and slaveOk=false error

后端 未结 5 1302
忘掉有多难
忘掉有多难 2020-12-30 19:34

I\'m getting a strange error in my node.js app

not master and slaveOk=false code 13435

I\'m doing a findOne query using mongoose 4.0.2 hitting a

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 20:07

    I solved this by simply fixing the URI my Node.js application was using to connect to MongoDB with Mongoose.

    When this error ocurred, my URI was

    mongodb://user:password@host:port/datatabase,

    and this was giving me the error not master and slaveOK=false.

    Then I changed the URI to add the Replica Set information, and the URI became something like this:

    mongodb://user:password@host:port,replicaSetHost:replicaSetPort/database?replicaSet=rs-someServer.

    Now, I don't know if this is a general pattern, because this configuration is the one used by MongoLab, which is where my DataBase is hosted. However, it's likely you will solve the problem by adding the replica set information in the URI as well.

提交回复
热议问题