A. An error because deleteMany does not return deletedCount.
B. The entire deleted documents array.
C. Number of documents deleted with status 'inactive'.
D. Undefined because deleteMany returns nothing.
Solution
Step 1: Understand deleteMany return value
deleteMany() returns an object with deletedCount indicating how many documents were deleted.
Step 2: Analyze the console.log statement
The code logs result.deletedCount, so it outputs the number of deleted documents matching the filter.
Final Answer:
Number of documents deleted with status 'inactive'. -> Option C
Quick Check:
deleteMany() returns deletedCount [OK]
Hint: deleteMany returns deletedCount in result object [OK]
Common Mistakes:
Expecting deleted documents array
Assuming deleteMany returns nothing
Confusing deletedCount with total documents
4. Identify the error in this Express Mongoose code snippet for deleting a document:
Model.deleteOne({ _id: id }, (err, doc) => {
if (err) console.log(err);
else console.log(doc);
});
medium
A. The filter object is missing required fields.
B. The deleteOne method does not accept a callback.
C. The method should be deleteMany to delete one document.
D. The callback parameter doc should be result to access deletion info.
Solution
Step 1: Check callback parameters for deleteOne
The second callback parameter is a result object, not the deleted document itself.
Step 2: Understand what doc represents
It should be named result or similar to reflect it contains deletion info like deletedCount, not the document.
Final Answer:
The callback parameter doc should be result to access deletion info. -> Option D
Quick Check:
Callback gets result info, not deleted doc [OK]
Hint: Callback second param is result info, not deleted doc [OK]
Common Mistakes:
Expecting deleted document in callback
Using deleteMany when only one document needed
Assuming deleteOne does not accept callbacks
5. You want to delete all documents where the field active is false, but only if the user confirms. Which Express code snippet correctly handles this with error checking?
hard
A. Model.deleteMany({ active: false }, (err, res) => {
if (err) throw err;
console.log(res);
});