MongoDB Delete

From mi-linux
Revision as of 13:05, 21 October 2016 by Cm1958 (talk | contribs) (Created page with "Main Page >> MongoDB >>MongoDB Workbook >> Deleting a Document == Deleting a Document == At some stage you may want to delete a document...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Main Page >> MongoDB >>MongoDB Workbook >> Deleting a Document

Deleting a Document

At some stage you may want to delete a document from a collection. The format is:

db.collection.deleteOne(query_criteria) /* deletes the first document found that matches the query criteria */
db.collection.remove(query_criteria) /* deletes all documents found that matches the query criteria */

Delete Department 40

Department 40 has closed down:

db.deptCollection.deleteOne({"deptno":40})

Note, if the query_criteria only returns one document, remove() and deleteOne() will have the same effect.