【发布时间】:2015-03-30 21:14:12
【问题描述】:
我的游戏家族收藏看起来像这样
{
"_id": ObjectId('54cc3ee7894ae60c1c9d6c74'),
"game_ref_id": "REF123",
..
"yearwise_details": [
{
"year": 1,
...
"other_details": [
{
"type": "cash",
"openingstock": 988
..
},
{
"type": "FLU",
"openingstock": 555
..
},
..other items
]
},
{
"year": 2,
...
"other_details": [
{
"type": "cash",
"openingstock": 3000,
....
},
...
{
"type": "ghee",
"openingstock": 3000,
...
},
..
]
}
]
}
我的更新查询
db.gamefamilies.update({"game_ref_id": "REF123", "teamname": "manisha","yearwise_details.year": 2, "yearwise_details.other_details.type": "ghee"}, {"$设置": {"yearwise_details.0.other_details.$.openingstock": 555} });
文档被正确拾取。我希望更新第 2 年的 item type="ghee" 但第 1 年的第 2 项(FLU 类型)会更新。我做错了什么?
任何帮助将不胜感激。
问候 玛尼莎
【问题讨论】:
-
尝试制作 {yearwise_details.1.other_details.$.openingstock": 555}
标签: mongodb