Sharing an open connection with two instances.

14 views
Skip to first unread message

Eric Rini

unread,
Jul 25, 2016, 11:05:09 AM7/25/16
to Mongoose Node.JS ODM
Hello, I'd like to find a way to share an open connection with two separate instances of mongoose. Here's an example.

var mongoose = require('mongoose');
mongoose.connect('foo/bar');

var instance1 = new mongoose.Mongoose();
var instance2 = new mongoose.Mongoose();


// This is sharing the ENTIRE Mongoose.Connection object, which has all the models, logging functions, etc. What I want to share is ONLY the open mongodb client connection and nothing else.

instance1.connection = mongoose.connection;
instance2.connection = mongoose.connection;

Is it possible to do something like this? The reason for wanting to do this is to have a separate mongoose instance for each request processed by a server, so that all queries\logs generated by that request can be meta tagged with a specific request context different from all other requests. 
Reply all
Reply to author
Forward
0 new messages