const tsetSchema=new mongoose.Schema({
name:String
views:Number
},{timestamps:true})
I specified the timestamp when creating the schema, so when I update the document, updatedAt and createdAt will be automatically updated for me.
But now I want to not update the updatedAt field when updating the views field, but only need to update the views. How to do this?
You can consider using Mongoose middleware to meet your needs, such as schema.pre or schema.post.
Schema also uses Mongoose’s middleware to specify timestamps.
For reference.
Love MongoDB! Have fun!
The 2017 MongoDB Chinese Community Beijing User Group Conference is coming soon, June 3, 2017 13:00-18:00
Registration now! Please click on the left!