Mongoose: Read on ReplicaSet

后端 未结 6 1976
暖寄归人
暖寄归人 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:33

    You can simply do that by using below code

    var collection = db.collection(collectionName,{readPreference:'secondaryPreferred'});
    

    http://p1bugs.blogspot.in/2016/06/scaling-read-query-load-on-mongodb.html

提交回复
热议问题