3

使用 MongoDb NORM 驱动程序,有谁知道是否可以将光标移到类似于下面的“查询”集合,以便可以检索文档的“页面”以及查询文档的总数?

> var j = db.People.find().skip(2).limit(2)
> j.count()
13
> j
{ "_id" : NumberLong(25), "Name" : "Ted" }
{ "_id" : NumberLong(26), "Name" : "Tom" }

正如我假设以下执行 MongoDbquery 两次...

totalItems = peopleCollection.Count(queryExpando);

peopleList = peopleCollection.Find(queryExpando, orderByExpando, pageSize, startIndex).ToList();
4

1 回答 1

0

I am not sure if there is another way, but you can probably use LINQ to do what you need:

var allItems = peopleCollection.AsQueryable();
var count = allItems.Count();
var peopleList = allItems
                 .Where(p => p.Field == fieldValue)
                 .OrderBy(p => p.OrderByField)
                 .Skip(startIndex)
                 .Take(pageSize);
于 2011-09-06T23:13:40.600 回答