Event Monitoring with Mongoose
I previously wrote about MongoDB Driver Monitoring, but there are ODM libraries and framework integrations that are built atop the drivers that can take advantage of this functionality.
For example, mongoose
can be easily configured to expose cluster monitoring, connection pool monitoring and command monitoring capabilities.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const mongoose = require('mongoose');
const { Schema } = mongoose;
run().catch(err => console.log(err));
async function run() {
await mongoose.connect('mongodb://localhost:27017/test');
mongoose.connection.getClient().on('connectionCheckOutStarted', ev => console.log('Received: ', ev));
const schema = Schema({ name: String });
const Test = mongoose.model('Test', schema);
await Test.create({ name: 'test' });
}
This was documented within a comment of this GitHub issue but for the sake of visibility I wanted to capture it here.
This post is licensed under CC BY 4.0 by the author.
Comments powered by Disqus.