Consider a MongoDB collection with 1000 documents. You run db.collection.estimatedDocumentCount(). What does this method return?
db.collection.estimatedDocumentCount()
Think about whether this method uses filters or scans all documents.
estimatedDocumentCount() returns a fast, approximate count of all documents in the collection without applying any filters. It is faster than countDocuments() which applies filters and counts exactly.
Which reason best explains why you might choose estimatedDocumentCount() instead of countDocuments()?
Think about speed and how the method counts documents.
estimatedDocumentCount() is faster because it uses collection metadata to estimate the number of documents, avoiding scanning all documents. It does not apply filters and is approximate.
Choose the correct way to get the estimated document count from a MongoDB collection using Node.js MongoDB driver.
const count = await collection.???();
Check the exact method name for estimated count.
The correct method name is estimatedDocumentCount(). Other options are either deprecated or incorrect.
You want to count documents matching a filter in a large collection. Why might estimatedDocumentCount() be a bad choice?
Think about whether filters are applied.
estimatedDocumentCount() does not accept filters and returns an approximate count of all documents. For filtered counts, use countDocuments().
You run estimatedDocumentCount() on a collection after deleting all documents, but it still returns a non-zero number. Why?
Think about how metadata updates in MongoDB.
estimatedDocumentCount() relies on collection metadata which may lag behind actual document deletions, causing it to return outdated counts temporarily.