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

后端 未结 2 1750
眼角桃花
眼角桃花 2020-12-31 18:16

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 val

相关标签:
2条回答
  • 2020-12-31 18:53

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

    Console.WriteLine(collection.Find(query).SetSkip(0).SetLimit(1).Size());
    
    0 讨论(0)
  • 2020-12-31 19:00

    Looks like it is now

    Console.WriteLine(collection
        .Find(filter)
        .Skip(30)
        .Limit(30)
        .Count());
    
    0 讨论(0)
提交回复
热议问题