Mongoose: Read on ReplicaSet

后端 未结 6 1968
暖寄归人
暖寄归人 2021-01-02 21:57

I have a mongodb replica set from which I want to read data from primary and secondary db.

I have used this command to connect to the db:

mongoose.con

6条回答
  •  长发绾君心
    2021-01-02 22:52

    As well as setting the connection URI (as you did) and the connection options (as Emas did), I also had to explicitly choose the server for each query, e.g.

    var query = User.find({}).read("nearest");
    query.exec(function(err, users) {
        // ...
    });
    

提交回复
热议问题