Full-Stack Web Development with Vue.js and Node

(singke) #1
Introducing MongoDB Chapter 3

The only difference between updateOne() and updateMany() is
that updateOne() updates only the first document that is matched
whereas updateMany() updates all the documents that are matched.

update()

Just like insert, the update() command does the job for updateOne() and updateMany().


To remove confusion, we can just use the update() command instead of updateOne()


and updateMany():


> db.users.update(
{ "name": "John" },
{
$set: { "email": "[email protected]" }
}
)

The output is as follows:


Deleting documents


MongoDB provides multiple commands for deleting and removing documents from


collections.


deleteOne()

deleteOne() removes only a single document from a collection:


> db.users.deleteOne( { name: "John" } )
Free download pdf