Update multiple documents with different field value by id set. Mongoose 1

Update multiple documents with different field value by id set. Mongoose

You can not update two documents at once with a MongoDB query. You will always have to do that in two queries. You can of course set a value of a field to the same value, or increment with the same number, but you can not do two distinct updates in MongoDB with the same query.

Here is what the above code is Doing:
1. We’re using the $set operator to set the value of the “last_name” field to “Smith”.
2. We’re using the $inc operator to increment the value of the “age” field by 1.
3. We’re using the $push operator to add the value “hiking” to the “interests” array.
4. We’re using the $currentDate operator to set the value of the “last_modified” field to the current date.

Similar Posts