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
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.