0
0
MongoDBquery~20 mins

estimatedDocumentCount for speed in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Estimated Count Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What does estimatedDocumentCount() return?

Consider a MongoDB collection with 1000 documents. You run db.collection.estimatedDocumentCount(). What does this method return?

MongoDB
db.collection.estimatedDocumentCount()
AThe exact count of documents matching a query filter.
BThe size of the collection in megabytes.
CA list of all documents in the collection.
DAn approximate count of documents in the collection, usually fast and without filters.
Attempts:
2 left
💡 Hint

Think about whether this method uses filters or scans all documents.

🧠 Conceptual
intermediate
2:00remaining
Why use estimatedDocumentCount() over countDocuments()?

Which reason best explains why you might choose estimatedDocumentCount() instead of countDocuments()?

ABecause it provides an exact count with filters applied.
BBecause it is faster and uses collection metadata without scanning documents.
CBecause it returns documents instead of counts.
DBecause it updates the collection size automatically.
Attempts:
2 left
💡 Hint

Think about speed and how the method counts documents.

📝 Syntax
advanced
2:00remaining
Which code correctly uses estimatedDocumentCount() in Node.js?

Choose the correct way to get the estimated document count from a MongoDB collection using Node.js MongoDB driver.

MongoDB
const count = await collection.???();
AestimatedCount()
BcountDocuments()
CestimatedDocumentCount()
Dcount()
Attempts:
2 left
💡 Hint

Check the exact method name for estimated count.

optimization
advanced
2:00remaining
When is estimatedDocumentCount() NOT suitable?

You want to count documents matching a filter in a large collection. Why might estimatedDocumentCount() be a bad choice?

ABecause it only returns an approximate count of all documents without filters.
BBecause it is slower than scanning all documents.
CBecause it modifies the documents during counting.
DBecause it returns the size of the collection in bytes.
Attempts:
2 left
💡 Hint

Think about whether filters are applied.

🔧 Debug
expert
2:00remaining
Why does estimatedDocumentCount() return a non-zero number after deleting all documents?

You run estimatedDocumentCount() on a collection after deleting all documents, but it still returns a non-zero number. Why?

ABecause estimatedDocumentCount() uses collection metadata that may not update immediately after deletions.
BBecause the method counts documents with filters by default.
CBecause the collection is locked and cannot be counted.
DBecause estimatedDocumentCount() counts only documents in the cache.
Attempts:
2 left
💡 Hint

Think about how metadata updates in MongoDB.