Hello,
I don’t know why itemsNumber does not get decremented… Could someone help me ?
Products.update(pId, {
$inc: {itemsNumber: -1}, // decrement the items number
$push: { // add a payment information
payments: {
date: new Date(),
orderId: orderId,
transactionId: transId,
status: "sold"
}
}
});
Thanks,
Mickael.
Products.update({ _id: pId }, { $inc: { itemsNumber: -1 } }, {
$push: { // add a payment information
payments: {
date: new Date(),
orderId: orderId,
transactionId: transId,
status: "sold"
}
}
});
Untested but try to separate like this.
fermuch
3
That should work. What problem do you have? It does nothing or it throws an error?
The problem is that the push is done, I have a new “payments” info, but the number “itemsNumber” does not change.
It works with 2 differents lines
OrbiterProducts.update(pId, {$inc: {itemsNumber: -1}}); // decrement the items number
OrbiterProducts.update(pId, {
$push: { // add a payment information
payments: {
date: new Date(),
orderId: orderId,
transactionId: transId,
status: "sold"
}
}
});
fermuch
6
That’s bizarre, it should work the original way! Can you submit an issue?
should be
Products.update({ _id: pId }, { $inc: { itemsNumber: -1 }, // remove extra object here
$push: { // add a payment information
payments: {
date: new Date(),
orderId: orderId,
transactionId: transId,
status: "sold"
}
}
});