1

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.

tjoshi
  • 11
  • 3
  • Weird, that should work fine. There must be something else going on here. – JohnnyHK May 01 '14 at 00:36
  • are you able to check the MongoDB logs for the relevant period of time and see what is happening? Are you sure your app does not has any kind of singleton registration kind of tricks? – aks May 01 '14 at 02:46
  • Thanks guys - it was an issue with the allowed connections on the mongo server. I restarted the server and created more space to allow more connections. That fixed it! – tjoshi May 01 '14 at 22:24

1 Answers1

0

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.

tjoshi
  • 11
  • 3