Introducing MEVN Chapter 1
Updating documents
This command is used when we want to update a certain part of a collection. Let's say we
want to update the description of a post whose title is Vue.js; we can run the following
command:
> db.posts.updateOne(
{ "title" : "MEVN" },
{ $set: { "description" : "A frontend framework for Javascript
programming language" } }
)
The output for this command will be:
We can see here that the matchedCount is 1 , which means that as regards the parameter
that we sent to update the record with the title MEVN, there was one document in the posts
collection that matched the query.
The other key called modifiedCount gives us the count of the documents that got
updated.
Deleting documents
The delete command is used to remove documents from a collection. There are several
ways to delete a document from MongoDB.
Deleting documents that match a given criteria
To remove all the documents with certain conditions, we can run:
> db.posts.remove({ title: 'MEVN' })
This command will remove all the documents from the posts collection whose titles
are MEVN.