Deepak jha
Deepak jha

Reputation: 308

Get count of a database in MongoDB

I am trying to get count of all the documents of all the collections in a single MongoDB database.
For now, I am looping through all the collections to get the total count.
Is there any way (MongoDB command/ NodeJS way) of achieving this?

Upvotes: 1

Views: 169

Answers (1)

Risto Novik
Risto Novik

Reputation: 8295

What about using db.stats() and db.collection.stats() queries (https://docs.mongodb.com/manual/reference/method/db.collection.stats/) ? Which returns the number of collections and the objects.

Upvotes: 1

Related Questions