MongoDB | Document Deletion in MongoDB
29K views
Oct 24, 2024
Document Deletion in MongoDB
View Video Transcript
0:00
In this video we are discussing document deletion in MongoDB
0:06
So to delete the documents we will use the method that is a remove
0:12
So to delete document we are using the method that is known as the remove and syntax will
0:18
be like this that is DB freeliction name. Remove and as a parameter will be passing the selection logic
0:26
So to remove all entries we will use the remove command in this particular syntax, that is db
0:33
Dot collection name . Remove within this first brackets, we'll be using
0:38
this curle braces here. So to understand this concept better, let us go for one practical demonstration
0:44
for the easy understanding of this remove operation on MongoDB. In this video, we shall discuss how we can perform
0:52
the delete operation on MongoDB databases So here we having one database that is the My Database and we are having one collection that is a employee and this is the current content of the collection that is a db if we execute this query we getting the current
1:10
content of this collection so this is the current content. So now let us execute some
1:15
queries for performing the deletion operation. So the first query we are taking that
1:21
delete those documents where the age is 23. So here you can find we're having this this particular this particular document and this another
1:31
document these two documents are having the age value is equal to 23 in the rest of the cases
1:35
there is no age value equal to 23 so they are going to get deleted because they have been
1:41
asked for okay so i'm just marking them so now what what is the query query is that delete those
1:48
documents where the age is 23 so we'll be writing in this way dbd employee
1:56
the method will be removed the method will be removed so i shall go for this method remove so remove then I passing one parameter so that is the H colon so H colon then I shall go for
2:13
another culibrous dollar EQ EQ stands for equal to colon 23 so this is a way
2:21
in which you can type this query so another cul-reblase to complete and then
2:26
one first bracket so in this way we have written this one so look at the syntax that is that db
2:32
employee employee is the collection name dot remove is the method age equal to 23 so in
2:38
this way the things are to be written so now we are going for this enter so remove
2:44
two so number of removed is two so we are going for the find now so i can i expect that
2:52
borun and be wake these two name related tuples the respective document will get deleted and you can find that we having the one two three four five six seven so out of this seven we having only five documents are present now the last another query we going to execute
3:13
on this delete operation so delete all documents from the collection so if we shall be
3:19
going for dbd employee then we shall go for remove so delete all documents from the collection so
3:29
dot employee dot remove but here in this case we're not passing any argument so one
3:36
blank JSON object void this JSON object so it is like a truncate command in our SQL
3:43
so if I go for this if I execute this one so removed the number of removed is 5
3:50
so if you go for DB dot employee dot find method we're finding that is nothing
3:55
here so in this way in this demonstration you have shown you that
3:59
how to perform the delete operation on our MongoDB databases. Thanks for watching this video
#Programming