collection.count()¶
Definition¶
collection.count()
¶
Return the number of documents in a collection or view that match the specified query filter.
Usage¶
Example¶
To call the collection.count()
action from a Function, get a collection handle with
database.collection()
then call the handle's
count()
method.
collection.count({ status: "Complete" }) .then(numDocs => console.log(`${numDocs} documents match the specified query.`)) .catch(err => console.error("Failed to count documents: ", err))
Parameters¶
The collection.count()
action has the following form:
count(query)
Parameter | Description |
---|---|
Query Filter query: <document> | Optional. A standard MongoDB query document that specifies which documents to count. You can use most query selectors except for evaluation, geospatial, or bitwise selectors. Specify an empty query filter ( |
Return Value¶
The collection.count()
action returns a Promise that
resolves to the integer number of documents in the collection
that match the query filter.
Promise<numDocs: Number>
Value | Description |
---|---|
Count Result numDocs: <integer> | The number of documents in the collection that match the provided query filter. |
Give Feedback