मैं मोंगोज़ के साथ एक दस्तावेज़ को अपडेट करने का प्रयास करता हूं और यह विफल रहता है। क्वेरी मैं सफल मोंगो में सीधे निष्पादित कर सकते हैं है की तरह:
db.orders.update(
{
orderId: 1014428,
'delivery.items.id': '5585d77c714a90fe0fc2fcb4'
},
{
$inc: {
"delivery.items.$.quantity" : 1
}
}
)
जब मैं नेवला के साथ निम्न अद्यतन आदेश चलाने का प्रयास:
this.update(
{
orderId: this.orderId ,
"delivery.items.id": product.id
},
{
$inc: {
"delivery.items.$.quantity" : 1
}
}, function (err, raw) {
if (err) {
console.log(err);
}
console.log('The raw response from Mongo was ', raw);
}
);
मैं निम्न त्रुटि देखें:
{ [MongoError: cannot use the part (items of delivery.items.id) to traverse the element ({items: [ { quantity: 1, price: 6.9, name: "Manipulationstechniken", brand: null, id: "5585d77c714a90fe0fc2fcb4" } ]})]
name: 'MongoError',
message: 'cannot use the part (items of delivery.items.id) to traverse the element ({items: [ { quantity: 1, price: 6.9, name: "Manipulationstechniken", brand: null, id: "5585d77c714a90fe0fc2fcb4" } ]})',
index: 0,
code: 16837,
errmsg: 'cannot use the part (items of delivery.items.id) to traverse the element ({items: [ { quantity: 1, price: 6.9, name: "Manipulationstechniken", brand: null, id: "5585d77c714a90fe0fc2fcb4" } ]})' }
The raw response from Mongo was { ok: 0, n: 0, nModified: 0 }
मैंने इतनी सारी चीजों की कोशिश की। इस पर कोई सलाह?
के रूप में स्कीमा का अनुरोध:
var Order = new Schema({
orderId: Number,
orderDate: String,
customerName: String,
state: Number,
delivery: {
items: {type: Array, default: []},
state: { type: Number, default: 0 }
}
});
जब मैंने कोशिश की तो ठीक काम किया। 'This.update' कॉल में' यह' क्या है? – JohnnyHK
"यह" मॉडल फ़ंक्शन के अंदर है, इसलिए यह मॉडल से है - इस मामले में ऑर्डर। –