Getting an item count with MongoDB C# driver query builder

后端 未结 2 1302
眼角桃花
眼角桃花 2021-02-14 05:14

Using the c# driver for MongoDB I can easily construct a query against which I can then add SetSkip() and SetLimit() parameters to constrict the result set to a certain size.

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-14 05:35

    I'm using the Driver 2.3.0 and now is also possible to do that like this:

    ...
    IMongoCollection Collection = db.GetCollection(CollectionName);
    var yourFilter = Builders.Filter.Where(o => o.prop == value);
    long countResut = Collection.Count(yourFilter);
    

提交回复
热议问题