'Mongoose - Get nr of updates to specific Document

I have a collection of documents, the Schema looks like this:

{
  "name": String,
  "updates": {
    type: Number, 
    default: () => 0
  }
}

Now I have several API-endpoints that all do modify documents of this schema. Is it possible to do the increment the updates-count automatically when the document is updated, e.g., with a mongoose- oder mongodb-"middleware"?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source