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