Can someone help me how to properly make a update increment query for my data
For example I would like to increment the quantity of Unix Mug by 1, by the user with email: "[email protected]"
This one doesn't work for me
UserData.updateOne({email: email}, { $inc : {items: [{quantity: 1}]}})
asked Sep 4, 2022 at 4:50
Parzival
1291 gold badge2 silver badges13 bronze badges
-
Please share the data as snippet instead of image. Thanks.Yong Shun– Yong Shun2022年09月04日 04:51:38 +00:00Commented Sep 4, 2022 at 4:51
1 Answer 1
You can use the positional operator ($) as shown below:
db.users.updateOne({
email: "USER_EMAIL",
"items.productName": "Unix Mug"
}, {
$inc: {
"items.$.quantity": 1
}
})
answered Sep 4, 2022 at 5:01
Dharmaraj
51.3k8 gold badges68 silver badges100 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js