LoginSignup
1
0

More than 1 year has passed since last update.

mongoose の接続状態をチェックする。

Last updated at Posted at 2023-02-03

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

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0