mongodb - Document update issues about mongoose
淡淡烟草味
淡淡烟草味 2017-05-31 10:35:31
0
1
813
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?

淡淡烟草味
淡淡烟草味

reply all(1)
过去多啦不再A梦

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!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template