我的数据库中有这个文档:
[
{
"_id": "53dc97bf91f1f933e15d6fb1",
"attributes": {
"chilled": false,
"flammable": false,
"food": false,
"fragile": false,
"frozen": false,
"hot": false,
"outsized": false
},
"createdAt": "02/08/14 09:48:16",
"customer": "53d68bc091f1f933e15d6f90",
"location": [
{
"count": 0,
"warehouse": "53db430c91f1f933e15d6fa6"
},
{
"count": 34,
"warehouse": "53db430c91g1f933e45d6fa4"
},
],
"name": "test",
"type": "stored",
"updatedAt": ""
}
]
如果我知道仓库 ID,如何更新位置数组?这就是我现在拥有的
coll := p.GetDb().C("product")
changes := bson.M {
"location": bson.M {
"$elemMatch": bson.M {
"warehouse": bson.ObjectIdHex(warehouseId),
},
},
"$set": bson.M {
"location.$.count": 4,
},
}
err := coll.UpdateId(bson.ObjectIdHex(productId), changes)
if err != nil {
http.Error(res, err.Error(), 500)
return
}
但是得到这个错误:
'location.$elemMatch' 中的美元 ($) 前缀字段 '$elemMatch' 对存储无效。