mongodb connection과 연결여부 monitoring

less than 1 minute read

간단한 코드 기록용

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
let mongoose  = require('mongoose')

let conn1     = mongoose.createConnection('mongodb://localhost:5555/db1', {useNewUrlParser: true})
let conn2     = mongoose.createConnection('mongodb://localhost:5556/db2', {useNewUrlParser: true})

conn1.on('connected', () =>
{
    console.log("connected to mongodb conn1")
});
conn2.on('connected', () =>
{
    console.log("connected to mongodb conn2")
});
conn1.on('disconnected', () =>
{
    console.log("disconnected with mongodb conn1")
});
conn2.on('disconnected', () =>
{
    console.log("disconnected with mongodb conn2")
});