Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count items in MongoDB [closed]

Tags:

c#

mongodb

How do I get a count of all items in a Mongo collection, using the 2.x C# driver?

I'm trying to use CountAsync, which I need to pass in a filter. I don't want to filter - I want everything returned.

like image 287
Sam Avatar asked Dec 06 '25 05:12

Sam


1 Answers

You can always pass the empty document in the method like this

db.collection.CountDocumentsAsync(new BsonDocument());
like image 71
Devesh Avatar answered Dec 08 '25 18:12

Devesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!