我的收藏架构如下所示:
Products :{ _id: "S2oF6HitSKzwy5toz",
user_id: "LKAHKhK5SvTr6r8sK",
shop: "eBay.com",
items: {
item: "HP Laptop"
item_total: 101.67
notes: "note for hp laptop"
price: 101.67
quantity: 1
shop: "eBay.com"
url: "ebay.com/hp"
},
expenses: {
bank_fee: 0
cod_fee: 0
expense_total: 0
inbound_fee: 0
pcs_fee: 0
pjp_fee: 0
},
service_fee: 15.25,
total: 116.92
}
我想使用以下语法使用bank_fee
查询更新expenses
子文档中的update
字段:
insertFee : function(user_id, id, fee_amount){
Products.update({user_id: user_id, _id: id}, {$set: {"expenses.$.bank_fee":fee_amount}});
}
然而它会引发错误:
Exception while invoking method 'insertFee' MongoError: can't append to array us
ing string field name [$]
我在这里做错了什么?
P.S。我正在关注this doc以进行更新操作。