Question

I have two node servers running on a single box (ports 3030 and 3031) and am trying to connect to the same MongoDB server (different databases) using Mongoose, but it only lets one application connect and the other one fails. I've tried:

// App 1
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/db1');

// App 2
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/db2');

The connections are mutually exclusive. When App 1 connects, App 2 fails with "Connection closed" and vice-versa.

//App 1
var mongoose = require('mongoose');
var conn = mongoose.createConnection('mongodb://mongoserver/db1');
var model = conn.model('collection1');

//App 2 
var mongoose = require('mongoose');
var conn = mongoose.createConnection('mongodb://mongoserver/db2');
var model = conn.model('collection1');

Same result.

Has anyone been able to get this to work without creating some kind of broker app? Same box, multiple node apps, same MongoDB server, different databases, at the same time.

Was it helpful?

Solution

So it turns out that this wasn't an issue with node/mongoose as much as it was with the MongoDB server itself. I had reached the maximum capacity.

The limitation of connections is from operating system at 1024 open files ( 80% are used for connections).

So I had 820 connections available and I was using all of them. I cleared the connections and it worked.

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