mongodb 更新数组出现can't append to array using string field name

时间:2022-09-30 20:34:19

数据库内容大概如下:

{
_id:,
"hero_list" : {
"" : {
"stars" : ,
"_id" : ,
"equip" : [
[ ],
[ ],
[ ],
{
"item_id" : ,
"lv" : ,
"uuid" : "4a727ee1-e7b0-4265-b004-e2b75890378a",
"amount" :
},
[ ],
[ ]
],
"lv" : ,
"exp" : ,
"quality" :
}
}
}

> db.hero.update({_id:1},{$set:{"hero_list.15521.equip.4.lv":1}})
can't append to array using string field name [lv]

看了半天,原来是自己眼花,数组下标数错了

db.hero.update({_id:1},{$set:{"hero_list.15521.equip.3.lv":1}})

OK