Deleting Documents

View saved

Delete one

Removes the first match. Confirm the filter with find beforehand.

db.books.deleteOne({ title: "Temporary Draft" })

Delete many

Deletes every matching document. Empty filters are dangerous—avoid them unless you intend to clear a collection.

db.books.deleteMany({ archive: true })

Drop vs delete

Deleting documents keeps the collection. Dropping removes the collection (and its indexes) entirely.

// db.books.drop()

Soft deletes in apps

Many apps set deletedAt instead of hard deleting so they can recover or audit. Choose deliberately.

Comments

One comment per signed-in account. Comments are saved with this page’s URL.