1.0.2 • Published 6 years ago

mongoose-stats v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

mongoose-stats

mongoose stats plugin

Build Status npm Github Releases

API

stats event data

  • collection the mongodb collection
  • op the op function
  • use the time consuming of function
  • size the record count of function
  • options the query options, optional
  • conditions the query conditions, optional
  • fields the query fields, optional
  • update 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);