Problem Statement
What is returned when you successfully delete a document using deleteOne()?
Explanation
When you successfully delete a document using deleteOne, MongoDB returns an object containing two properties: acknowledged which is true if the operation was acknowledged by the server, and deletedCount which shows how many documents were deleted.
For deleteOne, deletedCount will be either zero if no document matched the filter, or one if a document was deleted. This return value helps you verify that the delete operation was successful and whether any documents were actually removed.
Code Solution
SolutionRead Only
// Delete one document
db.users.deleteOne({ name: "John" })
// Returns:
{
acknowledged: true,
deletedCount: 1
}
// If no match found:
{
acknowledged: true,
deletedCount: 0
}