猫鼬:在ReplicaSet上阅读 [英] Mongoose: Read on ReplicaSet

查看:70
本文介绍了猫鼬:在ReplicaSet上阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mongodb副本集,我想从该副本集中读取主数据库和辅助数据库的数据.

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.connect('mongodb://user:password@54.230.1.1,user:password@54.230.1.2,user:password@54.230.1.3/PanPanDB?replicaSet=rs0&readPreference=nearest');

它不起作用..我的应用程序继续从主数据库读取..有任何建议吗?

It doesn't work.. My application continues to read from the primary.. Any suggestion please?

推荐答案

按照猫鼬网站,您可以添加以下说明以在猫鼬上配置ReadPreference:

Following the documentation found on MongoDB website and on Mongoose web site, you can add this instruction for configuring the ReadPreference on Mongoose:

var opts = { replSet: {readPreference: 'ReadPreference.NEAREST'} };

mongoose.connect('mongodb://###:###@###:###/###', opts);

这已经使用Mongoose版本3.8.9进行了测试

This has been tested using Mongoose version 3.8.9

这篇关于猫鼬:在ReplicaSet上阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆