2
收藏:更新文件
{
"shopping_list": [
{
"date": 22,
"drinks": [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],
"year": 2016,
"month": 11
},
{
"date": 23,
"drinks": [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],
"year": 2016,
"month": 11
}
],
"password": "user",
"date_signup": "10-11-2016",
"name": "User",
"email": "[email protected]"
}
我所做的代碼:
data_1 = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]
data_2 = [2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000]
con.update({"email": "[email protected]",
"shopping_list.date": 23,
"shopping_list.month": 11,
"shopping_list.year": 2016},
{"$set": {"shopping_list.$.drinks": data_2}})
想這太(沒工作):
con.update({"email": "[email protected]",
"shopping_list.date": {"$eq": 23},
"shopping_list.month": {"$eq": 11},
"shopping_list.year": {"$eq": 2016}},
{"$set": {"shopping_list.$.drinks": data_2}})
使用我的代碼,我使用$set
將數組的第二個索引中的shopping_list
作爲目標。但我運行後沒有任何變化。我的代碼有什麼問題?
是的。這樣可行。謝謝。 – QuartZ