1

我的集合架构如下所示:

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中的字段:expensesupdate

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 [$] 

我在这里做错了什么?

PS我正在关注这个文档进行更新操作。

4

0 回答 0