Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# driver for MongoDb: how to use limit+count?

From MongoDb documentation: "On a query using skip() and limit(), count ignores these parameters by default. Use count(true) to have it consider the skip and limit values in the calculation." That's exactly what I need to count resulted elements for the specific query until it's over defined limit like 1000, but I do not see any way to do it in c# driver. Count of IMongoCollection and SetCount of IMongoCursor are both parameter-less. Any idea?

like image 432
YMC Avatar asked Oct 19 '12 01:10

YMC


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.


2 Answers

Use the Size method instead of Count, as that honors Skip and Limit.

Console.WriteLine(collection.Find(query).SetSkip(0).SetLimit(1).Size());
like image 54
JohnnyHK Avatar answered Sep 19 '22 06:09

JohnnyHK


Looks like it is now

Console.WriteLine(collection
    .Find(filter)
    .Skip(30)
    .Limit(30)
    .Count());
like image 21
Datum Geek Avatar answered Sep 18 '22 06:09

Datum Geek