4

I am connecting to the mongo servers that are not localhost. I am using mongoose. And in some moment I needed to connect with mongo native driver so I am doing it like:

mongoose.mongo.MongoClient.connect(uri, function (err, conn) {});

but conn object is null.

Recently I changed servers structure, and now all mongo databases are remote, and on my new node machines I do not have mongo shell installed at all... In first all was working fine and connection uri was:

mongodb://x.x.x.x:27017/database,mongodb://y.y.y.y,mongodb://z.z.z.z

where x.x.x.x:27017 was primary, after some time due the break of the initial primary, new primary has been elected, and now I am starting with the same uri, but connection object is null and I do not know why...

is there somebody that had similar problem? or maybe solution or idea....

Nenad
  • 65
  • 6
  • 1
    The `Mongoose ODM` (or any MongoDB drivers) do not rely on the `mongo` shell to connect. Drivers exchange messages directly with a `mongod` server (or `mongos`, for sharded clusters) using the [MongoDB Wire Protocol](http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/). I would suggest trying to connect from a `mongo` shell on your machine (or wherever you are running the Mongoose code from) to see if there is a general connectivity issue. It's possible that your remote `mongod` instance is blocking connections via a firewall or `bind_ip` directive. – Stennie Jan 22 '14 at 14:02
  • solution was that connection uri for the MongoClient was not correct... I was using same uri like I used in mongoose, but correct one was this one: `mongodb://x.x.x.x:27017,y.y.y.y:27017,z.z.z.z:27017/database` – Nenad Jan 22 '14 at 14:14

1 Answers1

2

Connection uri was wrong:

instead:

mongodb://x.x.x.x:27017/database,mongodb://y.y.y.y,mongodb://z.z.z.z,{options}

for native driver MongoClient I should used:

mongodb://x.x.x.x:27017,y.y.y.y:27017,z.z.z.z:27017/database?opt1=o1&opt2=o2

this is where I was found this solution: MongoClient.connect

Nenad
  • 65
  • 6