Mongoose data formatting

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

)?
Mar.30,2021

deal with it with moment.js

http://momentjs.com


what if you want to query list

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b34ddf-2b6c6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b34ddf-2b6c6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?