0

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}]}})

enter image description here

1
  • Please share the data as snippet instead of image. Thanks. Commented Sep 4, 2022 at 4:51

1 Answer 1

1

You can use the positional operator ($) as shown below:

db.users.updateOne({
  email: "USER_EMAIL",
  "items.productName": "Unix Mug"
}, {
  $inc: {
    "items.$.quantity": 1
  }
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.