【发布时间】:2020-08-02 00:13:51
【问题描述】:
在这里找到了很多类似的问题,但没有答案。
问题
假设我有以下猫鼬模式:
const mySchema = new mongoose.Schema({
sanePeoplesField: String,
comments: [
normalStuff: {type: Date, default: Date.now},
damNestedAgain: [String]
]
})
回顾一下,damNested array 在架构上的 comments array 内。
如果我很幸运并且想要更改 normalStuff(数组中的 obj),我会这样做:
mySchema.findOneAndUpdate({"comments._id": req.body.commentId},
{
$push:
{
comments: { normalStuff: 12122020 } }
}
})
这会用新值更新 normalStuff。
但是,我需要更新damNestedAgain 中的一个字段,但不知道如何访问它!
问题
在我的示例中,如何更新嵌套数组damNestedAgain 的嵌套数组?
【问题讨论】:
标签: arrays mongodb mongoose mongoose-schema