By default, update updates the first found data, and we do an experiment by inserting 3 C-1 data.
Db.test_collection.insert ({c:1})
And then we'll find a bit.
Db.test_collection.find ({c:1})
The result is
{"_id": ObjectId ("5b5e3f7da2b4848fd8c49dbf"), "C": 1"_id": ObjectId ("5b5e3f7fa2b4848fd8c49dc0"), "C": 1 "_id": ObjectId ("5B5E3F7FA2B4848FD8C49DC1"), "C": 1}
The instructions have been inserted successfully.
We updated the data for C to 1 to C 2 with update
Db.test_collection.update ({c:1},{c:2})
Let's look at the data for C 1 again.
Db.test_collection.find ({c:1})
We found two more.
We look for the data for C 2
Db.test_collection.find ({c:2})
Found only one
MongoDB is designed to prevent careless update errors
Db.test_collection.update ({c:1},{$set: {c:2}},false,true)
The 2nd set is a partial operation, and the 3rd parameter indicates if it is not present, if it is newly created, and the 4th parameter indicates whether to update more than one data, we can find the data of C 2.
Db.test_collection.find ({c:2})
We found 3.
MONGODB Basic Operation Data Update multiple data