0
0
MongoDBquery~10 mins

estimatedDocumentCount for speed in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the estimated number of documents in the collection.

MongoDB
const count = await collection.[1]();
Drag options to blanks, or click blank then click option'
AestimatedDocumentCount
BcountDocuments
Cfind
Daggregate
Attempts:
3 left
💡 Hint
Common Mistakes
Using countDocuments() which is slower because it scans documents.
Using find() which returns documents, not a count.
Using aggregate() which is for complex queries.
2fill in blank
medium

Complete the code to print the estimated document count from the collection.

MongoDB
collection.[1]().then(count => console.log(count));
Drag options to blanks, or click blank then click option'
AcountDocuments
Bfind
CestimatedDocumentCount
DdeleteMany
Attempts:
3 left
💡 Hint
Common Mistakes
Using deleteMany() which deletes documents instead of counting.
Using find() which returns documents, not a count.
Using countDocuments() which is slower.
3fill in blank
hard

Fix the error in the code to get the estimated document count correctly.

MongoDB
const count = await collection.[1];
Drag options to blanks, or click blank then click option'
AestimatedDocumentCount
BestimatedDocumentCount()
CcountDocuments()
DcountDocuments
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting parentheses after the method name.
Using countDocuments() which is slower.
Using property without calling it as a function.
4fill in blank
hard

Fill both blanks to estimate the document count and handle errors.

MongoDB
collection.[1]().catch(error => console.[2](error));
Drag options to blanks, or click blank then click option'
AestimatedDocumentCount
Berror
Cerror.log
Dconsole.error
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.log instead of console.error for errors.
Using countDocuments instead of estimatedDocumentCount.
Using error.log which is not a function.
5fill in blank
hard

Fill all three blanks to estimate document count, assign it to a variable, and print it.

MongoDB
async function getCount() {
  const count = await collection.[1]();
  console.[2]('Estimated count:', [3]);
}
Drag options to blanks, or click blank then click option'
AestimatedDocumentCount
Blog
Ccount
DcountDocuments
Attempts:
3 left
💡 Hint
Common Mistakes
Using countDocuments instead of estimatedDocumentCount.
Using console.error instead of console.log for printing count.
Printing the method name instead of the variable.