The $inc operator in MongoDB is used to increment the value of a field by a specified amount. It is commonly used to update numeric fields in documents. If the field does not exist, $inc will create it and set it to the specified value.
Example:
db.collection.updateOne(
{ _id: 1 }, // Filter to find the document
{ $inc: { quantity: 5 } } // Increment the 'quantity' field by 5
)
In this example, the quantity field of the document with _id 1 will be increased by 5. If quantity does not exist, it will be created with a value of 5.
