count-kommandoen tæller dokumenter i en collection eller et view.
Eksempel
db.runCommand({ count: "pets" })
Du kan tælle med et filter:
db.runCommand({ count: "pets", query: { type: "Dog" } })
Limit og skip
db.runCommand({ count: "pets", query: { type: "Dog" }, limit: 3 })
db.runCommand({ count: "pets", query: { type: "Dog" }, skip: 2 })
Kommandoen understøtter også felter som hint, comment, readConcern og collation.
MongoDB anbefaler nyere drivere at bruge countDocuments() og estimatedDocumentCount() i stedet.