Which SchemaType in Mongoose is Best for Timestamp?

后端 未结 6 1775
予麋鹿
予麋鹿 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 17:02

    First : npm install mongoose-timestamp

    Next: let Timestamps = require('mongoose-timestamp')

    Next: let MySchema = new Schema

    Next: MySchema.plugin(Timestamps)

    Next : const Collection = mongoose.model('Collection',MySchema)

    Then you can use the Collection.createdAt or Collection.updatedAt anywhere your want.

    Created on: Date Of The Week Month Date Year 00:00:00 GMT

    Time is in this format.

提交回复
热议问题