const Article = new Schema({
Title: { type: String, required: true },
Content: { type: String, required: true },
CreatedAt: { type: Date, default: new Date, get: v => moment(v).format("YYYY-MM-DD HH:mm")},
UpdatedAt: { type: Date, default: new Date, get: v => moment(v).format("YYYY-MM-DD HH:mm")},
})
ArticleModel.findOne({ _id: ArticleId }, "Title Content CreatedAt")
now the returned CreatedAt
is 2018-07-26T06:21:23.789Z
without formatting. If you set getters:true
:
Article.set("toJSON", { getters: true })
at this time, CreatedAt
is" 2018-07-26 14 code 21, but the result has more fields UpdatedAt
, so is there any way to query the method that the result is directly (_ id) Title Content CreatedAt
field and the time has been formatted in it