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.