Which SchemaType in Mongoose is Best for Timestamp?

后端 未结 6 1763
予麋鹿
予麋鹿 2020-12-07 16:08

I\'m using Mongoose, MongoDB, and Node.

I would like to define a schema where one of its fields is a date\\timestamp.

I would like to use this field in order

6条回答
  •  庸人自扰
    2020-12-07 16:57

    Edit - 20 March 2016

    Mongoose now support timestamps for collections.

    Please consider the answer of @bobbyz below. Maybe this is what you are looking for.

    Original answer

    Mongoose supports a Date type (which is basically a timestamp):

    time : { type : Date, default: Date.now }
    

    With the above field definition, any time you save a document with an unset time field, Mongoose will fill in this field with the current time.

    Source: http://mongoosejs.com/docs/guide.html

提交回复
热议问题