nodejs/mongoose: connect to db that’s using replica sets

i have installed mongodb (1.8.3) on two seperate servers and set them up to use “replica sets” as found here: http://www.mongodb.org/display/DOCS/Replica+Set+Tutorial

everything looks good so far: one server is recognized as primary, one as secondary (when i access them via commandline).

the problem is that i can’t connect to the DB using node.js
(0.4.10) and mongoose (2.1.0) like this:

var mongo = require('mongoose');
mongo.connectSet('mongodb://host/dbname,mongodb://host2/dbname');

i always get the following error message:

TypeError: Cannot read property 'reconnectWait' of undefined
    at new  (/var/www/node/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connections/repl_set_servers.js:23:31)
    at NativeConnection.doOpenSet (/var/www/node/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:80:18)
    at NativeConnection.openSet (/var/www/node/node_modules/mongoose/lib/connection.js:252:8)
    at Mongoose.connectSet (/var/www/node/node_modules/mongoose/lib/index.js:116:27)
...

searched around a bit and found a post somewhere saying that i also have to supply the name of the replica set – so i tried this instead:

mongo.connectSet('mongodb://host/dbname,mongodb://host2/dbname', rs_name:"name_replicaset"});

what am i doing wrong here …?!

Problem courtesy of: Philipp Kyeck

您可能感兴趣的

Wafer2 Node.js QuickStart 架构分析 与 Wafer1 的 Node.js Demo 采用 Express 不同,Wafer2 的 Node.js QuickStart 采用了 Koa.js 框架编写,Koa 将整个请求过程看做全异步的操作,使用 Node.js 7.6 开始支持的 async/await 语法,大大简化了整个应用开发...
Useful tools for your Node.js projects – 201... Back in the summer of 2015 we wrote a post on some useful tools that we were using in our Node.js projects . It’s proven to be a popular post, and a ...
Testing HTTP requests in node.js with express I have a simple authentication system I've made with a few post/get/dels on '/session' using express. I'd like to test this, but I can't seem...
Node is not launching I'm desperately trying to make node.js work again on Ubuntu 12.04 LTS. I installed it before 2-3 weeks ago and everything went f...
Node.js VS PHP — 你应该选择哪一个? 现在,Web开发公司和开发人员可以选择多种技术栈来构建Web应用程序。早期网络发展,不同的技术被用于前端和后端开发。但是,随着Node.js的发布,布局发生了变化,因为它允许开发人员使用 JavaScript 编写后端代码。这最终催生了MEAN(MongoDB + Express +Ang...
Node.js Recipes - The solution to all Node problems责编内容来自:Node.js Recipes - The solution to all Node problems (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » nodejs/mongoose: connect to db that’s using replica sets



专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录