0

I have a collection with a number field named "reference". I want to update every document in the collection and add 1000 to the reference field.

so if reference = 1 it will become 1001

pseudo below:

db.item.updateMany({}, {$set:{reference: reference+1000}}

Any idea how best to achieve this?

1 Answer 1

2

Use the $inc operator

db.item.updateMany({}, { $inc: { reference: 10000 }});
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.