Getting Started
What is MongoDB?
Install / Config
C.R.U.D. Ops
Data Modeling
Database Mgmt
Create, Read, Update and Delete Operations
Performing Modifications: Deleting Documents
How do you delete a single document?
.
db.collection.remove({query}, justOne = TRUE)
Can you delete a group of documents at one time?
.
db.collection.remove({query}, justOne = FALSE)
justOne
defaults to FALSE
Can you remove a single field?
.
db.collection.update({query},{$unset:{field:1}})
How do you delete a collection?
.
To remove all documents: db.collection.remove()
To remove the collection completely: db.collection.drop()
How do you remove a database?
.
Use the database
db.dropDatabase()
What problems can you run into when removing documents?
.
Be careful to not delete the wrong document!
Be aware that if the {query} provided to
remove()
is null ...
you could accidentally erase all documents in the collection!
+
o
-