Which method deletes the first matching document in a collection?
C
db.collection.deleteOne()
D
db.collection.deleteFirst()
Analysis & Theory
`deleteOne()` deletes the **first document** that matches the filter condition.
Which method deletes **all** documents that match a filter?
A
db.collection.removeAll()
B
db.collection.deleteMany()
D
db.collection.remove({ all: true })
Analysis & Theory
`deleteMany()` removes **all documents** matching the filter.
What does `db.users.deleteOne({ name: 'John' })` do?
A
Deletes all users named John
B
Deletes the first user named John
D
Deletes the entire collection
Analysis & Theory
`deleteOne()` removes only the **first** document where `name: 'John'`.
What happens if `db.collection.deleteMany({})` is executed?
A
Deletes the entire collection
B
Deletes only one document
C
Deletes all documents in the collection
Analysis & Theory
Passing an empty filter `{}` deletes **all documents** in the collection, not the collection itself.
Which method was used before `deleteOne()` and `deleteMany()`?
Analysis & Theory
`remove()` was the old method to delete documents; now replaced by `deleteOne()` and `deleteMany()`.
How can you check how many documents were deleted?
Analysis & Theory
`deletedCount` property of the result object shows how many documents were removed.
What happens if no document matches the filter in `deleteOne()`?
B
It deletes a random document
D
It deletes the last document
Analysis & Theory
If no match is found, nothing is deleted, and no error is thrown.
How do you delete all users whose `status` is `'inactive'`?
A
db.users.deleteOne({ status: 'inactive' })
B
db.users.deleteAll({ status: 'inactive' })
C
db.users.deleteMany({ status: 'inactive' })
D
db.users.removeAll({ status: 'inactive' })
Analysis & Theory
`deleteMany()` is used to remove all documents matching the condition.
Which command deletes the entire collection including its structure?
D
db.collection.deleteMany({})
Analysis & Theory
`drop()` deletes the whole collection, including all documents and metadata.
What does this query do: `db.inventory.deleteMany({ price: { $gt: 1000 } })`?
A
Deletes one expensive item
B
Deletes all items with price greater than 1000
D
Deletes all items with price less than 1000
Analysis & Theory
This deletes all documents where `price` is greater than 1000 using the `$gt` operator.