Question

I'm connecting to MongoDB using Mongoose in my node application.

I can see the below console.log logged once:

mongoose.connect(myURL)
var db = mongoose.connection
db.on('error', console.error.bind(console, 'connection error'))
db.once('open', function callback() { 
    console.log('Opening MongoDB Connection')
})

But in the MongoHQ live logs, I'm seeing 5 new connections open / close every-time I open or close the connection from the node(express) app. Why is this so and is it an issue with the code?

Also I have two candidates in the Live Log, candidate 0 and 13, where 13 is the one I'm actually connecting to. What is the candidate 0 there for? Is it just like a default for all MongoDBs in MongoHQ or it shouldn't be there?

Was it helpful?

Solution

I am not quite sure about the number of connections, but it could have something to do with default connection pool settings for Mongoose. The pool size, by default, is probably 5. Check the documentation here:

http://mongoosejs.com/docs/connections.html

Also, on the additional members, you are using MongoHQ Elastic Deployments. These are multi-member replica sets (giving you high availability in the event that the primary database has an issue). So, make sure that you check the documentation for how Mongoose handles replica set configurations. That way, your app will stay online if a replica set has a step down.

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top