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