node.js - Access multiple mongo databases with mongoose -
from within single nodejs app, how can switch between mongodb instances?
for context, i'm writing queue worker nodejs/zeromq/mongoose.
i have multiple nodejs/mongo apps running on same server, each own mongo database, push jobs queue.
my worker app pulls , processes jobs sequentially.
depending app sent job, needs connect appropriate mongo database through mongoose. apps use same mongoose models, same models available in worker app.
i'm having trouble switching connections , i'm afraid listing details of attempts/results muddy question here.
it doesn't matter if it's limited 1 @ time, or if maintain collection of connections.
any insight appreciated.
use createconnection
. see docs here: http://mongoosejs.com/docs/api.html. haven't done myself, believe create models attached each schema
var mongoose = require('mongoose'); var db = mongoose.createconnection(..); db.model('venue', new schema(..)); var ticket = db.model('ticket', new schema(..)); var venue = db.model('venue');
Comments
Post a Comment