- Reference >
- JavaScript Methods >
- cursor.count()
cursor.count()¶
-
cursor.
count
()¶ The
count()
method counts the number of documents referenced by a cursor. Append thecount()
method to afind()
query to return the number of matching documents, as in the following prototype:This operation does not actually perform the
find()
; instead, the operation counts the results that would be returned by thefind()
.The
count()
can accept the following argument:Parameters: - applySkipLimit (boolean) –
Optional. Specifies whether to consider the effects of the
cursor.skip()
andcursor.limit()
methods in the count. By default, thecount()
method ignores the effects of thecursor.skip()
andcursor.limit()
. SetapplySkipLimit
totrue
to consider the effect of these methods.See also
MongoDB also provides the shell wrapper
db.collection.count()
for thedb.collection.find().count()
construct.Consider the following examples of the
count()
method:Count the number of all documents in the
orders
collection:Count the number of the documents in the
orders
collection with the fieldord_dt
greater thannew Date('01/01/2012')
:Count the number of the documents in the
orders
collection with the fieldord_dt
greater thannew Date('01/01/2012')
taking into account the effect of thelimit(5)
:
- applySkipLimit (boolean) –