Database Reference
In-Depth Information
D
ELETING
D
ATA IN
M
ONGO
DB
The remove( ) function deletes one or more documents from a collection. The general
structure for a remove( ) statement is:
There are three parts to the remove( ) function:
•
Database
. We need to identify which database we are removing data from. More
accurately, the variable pointing to the database, such as in this case
db
.
•
Collection
. We need to identify the collection we are removing data from.
•
Parameters
. We need to identify the criteria for the documents that need to be re-
moved. Setting the justOne parameter to
true
or
1
removes just the first occurrence
of the criteria. If we leave out the justOne parameter or set it to
false
or
0
, all doc-
uments that meet the criteria will be removed.