How to make action when change in mongodb node.js?

If there is any way we can follow the change collection and call of callback? long googled and found nothing
Thank you in advance.
April 19th 20 at 11:59
1 answer
April 19th 20 at 12:01
it seems not, BUT it is possible in the schema to specify that before saving the document were performed on a function, called hooks a pre-save hooks or something like that

the documentation is pretty confusing, but there is

const schema = new mongoose.Schema({ name: String });

// Mongoose middleware will call this function, because this script adds
// the middleware to the schema before compiling the model.
schema.pre('save', () => console.log('Hello from pre save')); // this is

// Compile a model from the schema
const User = mongoose.model('User', schema);

new User({ name: 'test' }).save();
Thank you very much! - Madge.Spinka commented on April 19th 20 at 12:04
@Madge.Spinka, there is only the matter is that these hooks are only invoked on some certain operations, and each will need to hang your handler

two different for example'save', function(doc) {
 console.log('%s has been saved', doc._id);
});'remove', function(doc) {
 console.log('%s has been removed', doc._id);
- merle commented on April 19th 20 at 12:07

Find more questions by tags MongooseNode.js