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

java - Log4j2 configuration not found when running standalone application builded by shade plugin -

python - How do I create a list index that loops through integers in another list -