Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

383
Views
Count items in 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.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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

db.collection.CountDocumentsAsync(new BsonDocument());
over 4 years ago · Santiago Trujillo Report

0

db.collection.count()

In C# you can use Count() on the cursor of your collection.

over 4 years ago · Santiago Trujillo Report

0

Try as below:

var mongo = new Mongo();
mongo.Connect();
var db = mongo.GetDatabase("DatabaseName");
var collection = db.GetCollection<Product>();
var totalCount= collection.Count();

you can check in the following URL this url

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!