db.users.countDocuments({})

Category: Databases & SQL

db.users.countDocuments({})

Count documents in a collection

countDocuments({}) totals every document; pass a filter to count matches. It is the supported replacement for the deprecated count(). Related: find().limit(10) for a sample.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.