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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -