mongoose の接続状態をチェックする方法を紹介します。
// You can connect to MongoDB with the
mongoose.connect('mongodb://username:password@host:port/database?options...');
// You can check mongoose connection state
console.log(mongoose.connection.readyState);
ステータスは以下になります。
0: disconnected
1: connected
2: connecting
3: disconnecting
99 = uninitialized
【reference】
The search keyword is "how to connect with mongoose"
https://mongoosejs.com/docs/connections.html
The search keyword is "how to check if mongoose is connected"
https://stackoverflow.com/questions/19599543/check-mongoose-connection-state-without-creating-new-connection