Return the number of documents in a collection or view that match the specified query filter.

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))

The collection.count() action has the following form:


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 ({}) or omit this parameter to count all documents in the collection.

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>

Count Result

numDocs: <integer>
The number of documents in the collection that match the provided query filter.
Give Feedback