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' -

Google sheets equipment borrowing system -

c# - Ploeh AutoFixture was unable to create an instance from System.Runtime.Serialization.ExtensionDataObject -