How do I get cursor.count method in C# mongo Driver?

213 views
Skip to first unread message

Kunal Deshmukh

unread,
Apr 19, 2017, 6:21:06 AM4/19/17
to mongodb-user
Hi,

I am trying to count the number of records returned by query irrespective of limit operation. So that i can return to user total number of records for given search criteria. I want to achieve this using single query. This functionality is available with Core mongo implementation as seen here https://docs.mongodb.com/manual/reference/method/cursor.count/ .

I want to achieve this using C# driver.

Help Appreciated.

Kunal .

Robert Stam

unread,
Apr 21, 2017, 11:28:41 AM4/21/17
to mongod...@googlegroups.com
You can count the number of matching documents in a collection like this:

var builder = Builders<C>.Filter;
var filter = builder.Empty; // or build whatever filter you need
var count = collection.Find(filter).Count();



--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/185198d7-c66e-4198-b078-876664217230%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages