The simplest—and probably most common—type of update would be to update contact information. First, it's extremely important to test your update filter by using it in a db.collection.find() command. The reason why we use db.collection.find() instead of db.collection.findOne() is because you need to ensure that your update only affects the one customer! Thus, if we wish to change the email address and phone number for a fictitious customer named Ola Mann, we start with this command:
db.customers.findOne({ "email" : "[email protected]" });
Now that we have verified the existing customer email is correct and that our filter only affects one document, we are prepared to issue the update, as follows:
db.customers.updateOne(
{"email" : "[email protected]"},
{ $set: {
"email" : "[email protected]",
"phoneNumber" : "+94-111-222-3333...