mongoose stats plugin
stats event data
collection
the mongodb collectionop
the op functionuse
the time consuming of functionsize
the record count of functionoptions
the query options, optionalconditions
the query conditions, optionalfields
the query fields, optionalupdate
the update data, optional
const mongoose = require('mongoose');
const mongooseStats = require('mongoose-stats');
const {Schema} = mongoose;
const schema = new Schema({
name: String,
}, {
timestamps: true,
});
const Book = mongoose.model('Book', schema);
schema.plugin(mongooseStats, {
collection: 'Book',
});
schema.on('stats', (data) => {
// { collection: 'Book', op: 'save', use: 36, size: 1 }
console.info(data);
});
new Book({
name: '测试',
}).save().then(() => {
}).catch(console.error);