Skip to content
Justice Tech School

Counting Documents

countDocuments counts documents that match a filter. estimatedDocumentCount is a fast count of the whole collection from metadata.

Example
db.students.countDocuments({ city: "Lagos" })
db.students.estimatedDocumentCount()

Exercise

Count matches.

db.students.Documents({})

Quiz Test

Which count is fastest for the whole collection?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.