【发布时间】:2018-07-07 20:04:10
【问题描述】:
我需要使用 nodejs 更新 mongodb 中的嵌套数组。我试过this,但没有帮助,甚至没有抛出错误。
我的收藏是这样的
{
"country_details": [
{
"cities": [
"Abbeville"
],
"_id": "5a6ec189bb68bb09105eabe8",
"countryCode": "US",
"countryName": "United States"
}
],
"deletion_indicator": "N",
"_id": "5a6ec189bb68bb09105eabe7",
"date_created": "Mon Jan 29 2018 12:09:05 GMT+0530 (India Standard Time)",
"__v": 0
}
我想更新城市,我已经尝试过了
let query = {_id: "5a6ec189bb68bb09105eabe7", countryCode: "US", countryName: "United States"};
countryAndCitiesModel.collection.update(
query,
{$push: {"country_details.$.cities": "ABC"}},
(err, result)=> {
if(err){
return next(err);
}else{
return next(result);
}
});
没有得到更新,但得到结果就像是
{
"ok": 1,
"nModified": 0,
"n": 0
}
请帮忙..谢谢
【问题讨论】:
标签: arrays node.js mongodb mongoose mongodb-query