简体   繁体   中英

Listen for update operation in mongoDB and update certain field automatically

whenever any update operation occur on the collection, there should be an automated process in nodejs that will automatically update the timestamp for updateAt field.

I don't want to do manually as there are multiple sources from it can be updated.

MongoDB don't have any trigger, but there is a watch in MongoDB how can I use it.... I want to perform update operations inside the watch and don't want to trigger watch when we update it.

You can use post update hooks described here But for this particular purpose, you can use { timestamps: true } in your mongoose schema and it will automatically update the createdAt and updatedAt fields

If you are not using mongoose take a look at this question .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM