- Reference >
- JavaScript Methods >
- db.collection.count()
db.collection.count()¶
-
db.collection.count()¶ The
db.collection.count()method is a shell wrapper that returns the count of documents that would match afind()query; i.e.,db.collection.count()method is equivalent to:This operation does not actually perform the
find(); instead, the operation counts the results that would be returned by thefind().The
db.collection.count()method can accept the following argument:Parameters: - query (document) – Specifies the selection query criteria.
Consider the following examples of the
db.collection.count()methodCount the number of all documents in the
orderscollection:The query is equivalent to the following:
Count the number of the documents in the
orderscollection with the fieldord_dtgreater thannew Date('01/01/2012'):The query is equivalent to the following:
See also