1
更新的值我有一个MongoDB的集合内的下列文件:如何在多层文件
{
"_id":1,
"days":[
{
"date":"30-12-2015",
"label":"woensdag 30/12",
"delivery_options":{
"10:00-11:00":{
"capacity":5,
"orders":0,
"remaining_capacity":5
},
"11:00-12:00":{
"capacity":5,
"orders":0,
"remaining_capacity":5
},
...
}
},
{
"date":"31-12-2015",
"label":"donderdag 31/12",
"delivery_options":{
"10:00-11:00":{
"capacity":5,
"orders":0,
"remaining_capacity":5
},
"11:00-12:00":{
"capacity":5,
"orders":0,
"remaining_capacity":5
},
...
}
},
...
]
}
我想要做的是document['days'][1]['delivery_options']['11:00-12:00]['orders']
的值更新为1
。
这里就是我目前想:
MONGO[:delivery_options].find(_id: 1).update_one($set => {"days.1.delivery_options.11:00-12:00.orders" => 1})
但返回:
BSON::InvalidKey: NilClass instances are not allowed as keys in a BSON document.
我还能尝试一下呢?
你试过'MONGO [:DELIVERY_OPTIONS] .update_one({:_id => 1},{ “$设置”=> {“days.1.delivery_options。 11:00-12:00.orders“=> 1}})'? – chridam
这工作。如果你复制粘贴这个答案我可以接受它。谢谢。 – narzero