node.js - How to check if there is an existing MongoDB connection using mongoose? -


i have express app connects mongodb via mongoose, , have init script connect mongodb.

is there way detect if there existing connection db, not need connect again in script anytime want run it, there consequences connecting db multiple times via mongoose.

you can check using mongoose.connection.readystate,

ex.

var mongoose = require('mongoose'); console.log(mongoose.connection.readystate); 

the state return 1 if connected.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -