Key Takeaways About $inc Operator
- The $inc operator in MongoDB increments the value of a field by a specified amount.
- It can be used in embedded documents or arrays using dot notation.
- The $inc operator can be used in methods like update(), updateOne() according to requirements.
- Use of the $inc operator on a field with a null value will generate an error.
- It is an atomic operation within a single document.
MongoDB – $inc Operator
MongoDB $inc or increment operator is a type of field update operator. $inc operator increases the values of the fields to the specified amount or increases the field by the given value.
Important Points
- This operator accepts positive and negative values.
- If the given field does not exist, then this operator will create a field and set the value of that field.
- This operator will generate an error, if you use this operator with a null value field.
- It is an atomic operation in a single document.
Contact Us