Итак, у меня есть следующий бит кода, который обновляет мой latestComment
. Когда я console.log
обновил документ, в нем была дата. Однако, если я вернусь в свой MongoDB и проверим само поле, его там даже нет?
Вот пример выходных данных с текстовым комментарием из возвращенного документа
{ user: { userRecord: 5c9ba4d4347bb645e086527b },
picture: null,
video: null,
document: null,
text: 'Dwight Schrute',
date: 2019-04-18T18:51:31.207Z }
Фрагмент кода
CommentFeed.findOneAndUpdate(
{ _id: req.body.commentFeed },
{
$set: {
latestComment: {
user: {
userRecord: req.user._id
},
text: req.body.text,
picture: req.body.picture,
video: req.body.video,
document: req.body.document
}
}
},
{ new: true }
)
.then((feed) => {
console.log(feed.latestComment); <----I get the date timestamp here
...
Схема
CommentFeedSchema = new Schema({
latestComment: {
user: {
userRecord: {
type: Schema.Types.ObjectId,
ref: 'User'
}
},
text: { type: String },
picture: { url: { type: String }, blobName: { type: String } },
video: { url: { type: String }, blobName: { type: String } },
document: { url: { type: String }, blobName: { type: String } },
date: { type: Date, default: Date.now } <--Not saving
},
...