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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -