我有以下(简化的)数据结构:
{
quiz_id : ObjectId(),
questions : [{
question : "xyz",
options : [{
option_text : "a"
},
{
option_text : "b"
}]
}, {
question : "pqr",
options : [{
option_text : "s"
},
{
option_text : "t"
}]
}]
}
现在,我想通过将answer_count : 0
添加到每个选项来添加更新。所以新的数据结构是:
{
quiz_id : ObjectId(),
questions : [{
question : "xyz",
options : [{
option_text : "a",
answer_count : 0
},
{
option_text : "b",
answer_count : 0
}]
}, {
question : "pqr",
options : [{
option_text : "s",
answer_count : 0
},
{
option_text : "t",
answer_count : 0
}]
}]
}
在mongodb中如何做到这一点?
转载请注明出处:http://www.lechuangzk.com/article/20230526/2410177.html