1.0.2 • Published 7 years ago
mongoose-stats v1.0.2
mongoose-stats
mongoose stats plugin
API
stats event data
collectionthe mongodb collectionopthe op functionusethe time consuming of functionsizethe record count of functionoptionsthe query options, optionalconditionsthe query conditions, optionalfieldsthe query fields, optionalupdatethe 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);