search

Home  >  Q&A  >  body text

mongodb - Document update issues about mongoose

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?

淡淡烟草味淡淡烟草味2782 days ago826

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-31 10:37:31

    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!

    reply
    0
  • Cancelreply