So previously we've seen how to create, read and update using MongoDB in the Mongo shell. And now
it's time to look at how we would delete data from our collections.
And again if I scroll down in this CRUD documentation we've got a section that tells us how to do this.
And you can see that the two main methods we'll rely on is deleteOne and deleteMany.
And this is an example of how you would use it.
So you would say db.collection name.deleteMany or deleteOne and in the filter you would specify
which records you want to delete.
This is a good opportunity to translate what you see in the documentation to actual working code that
does what you want it to.
I want you to remove this second record that we added which is the pencil record by reading and using
the documentation on MongoDB.
Pause the video now and give that a try.
OK.
As we saw over here all we need to implement is db.collection
.deleteOne. And we're going to say db.products.deleteOne and then we're going to provide
the filter to find the particular record that we want to delete which in our case it would be easier
to just specify the id
and in this case that's going to be equal to 2.
So now if I hit enter then you can see that my request has been acknowledged and one record has been
deleted.
And now if we use that find method again you can see we only have one record in our products collection.