Connection to Mongo Replication Set - Node and Mongoose

1,983 views
Skip to first unread message

Flex

unread,
Apr 26, 2013, 12:31:35 PM4/26/13
to mongoo...@googlegroups.com
Hi All,

I have three servers running mongo in a replication.  All works here.

I have 1 app server running Node & Mongoose

My Mongoose connection string looks like this.
mongoose.connect('mongodb://myVM1/test,myVM2:27018/test,myVM3:27019/test');

The point of this is if a Mongodb Primary goes does the Mongoose driver will look at it's seed list and find the primary and continue operation.

Problem
What I have found is this that this only works if the Primary server actually is shut off, just killing the (Primary) mongod process forces the remaining two servers to re-elect primary yes, but the mongoose connection now throws an error.   connection error: [Error: no primary server found in set]

What can I do to the connection string to make this work better?

Thanks!
Flex

Aaron Heckmann

unread,
Apr 26, 2013, 1:44:02 PM4/26/13
to mongoo...@googlegroups.com
Which version of mongoose, node.js, and mongodb? Are you passing any connection options?


--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Aaron


Flex

unread,
Apr 26, 2013, 1:57:24 PM4/26/13
to mongoo...@googlegroups.com
Mongoose v3.6.8
Node:  v0.10.5
Mongodb 2.4.3

I'm passing in no options.

Aaron Heckmann

unread,
Apr 26, 2013, 2:39:53 PM4/26/13
to mongoo...@googlegroups.com
I'm not having luck reproducing when running the replica set locally. Are you running on separate boxes? Can you reach each of the other boxes your own? Can you connect to each node individually using mongoose (split out the connection string and try connecting to each one on its own). 

Flex

unread,
Apr 26, 2013, 2:47:22 PM4/26/13
to mongoo...@googlegroups.com
I have three separate VM's in my scenario.   Yes I can connect to each server separately (Command   mongo --host myVM1 --port 27017 or myVM2:27018 etc.)
The replication between all 3 servers are running perfectly, even when a primary goes down.



In the past I do recall putting 3 instances on one box and not having this problem.

Aaron Heckmann

unread,
Apr 26, 2013, 2:52:58 PM4/26/13
to mongoo...@googlegroups.com
Can you connect to each of them separately using mongoose?

mongoose.connect(singleNode)

Flex

unread,
Apr 26, 2013, 2:54:44 PM4/26/13
to mongoo...@googlegroups.com
Yes.

Flex

unread,
Apr 26, 2013, 2:57:43 PM4/26/13
to mongoo...@googlegroups.com
I pressed Post too fast.

Say I have A(P), B(S), C(S) and I kill A.  I wait to see where the next primary is, say C.  I can then connect Mongoose (C).

What is so weird is the connection the replSet works fine provide they actual VM is shut off.  Killing the mongo process just doesn't do it.  

Flex

unread,
Apr 26, 2013, 4:44:15 PM4/26/13
to mongoo...@googlegroups.com
I found the problem!  OMG!!

WRONG    >>  mongoose.connect('mongodb://myVM1:27018/test, myVM2:27017/test, myVM3:27019/test');
CORRECT >>  mongoose.connect('mongodb://myVM1:27018/test,myVM2:27017/test,myVM3:27019/test');

Yep all I did was remove the whitespace between the , and <host>!!!    I need a drink now!  It now works as it should.

Aaron Heckmann

unread,
Apr 26, 2013, 5:09:13 PM4/26/13
to mongoo...@googlegroups.com
Good to hear.
Reply all
Reply to author
Forward
0 new messages