public static IList <T> ToPage <T>(this MongoCollection <T> cols, int pageSize, IMongoQuery filterQuery, IMongoSortBy sort, out long totals, IMongoQuery currQuery = null) { sort = sort ?? new SortByDocument(); IList <T> list = new List <T>(); IMongoQuery query = new QueryDocument(); if (!currQuery.IsNull()) { query = Query.And(query, currQuery); } totals = cols.Count(query); if (!filterQuery.IsNull()) { query = Query.And(query, filterQuery); } list = cols.Find(query).SetLimit(pageSize).SetSortOrder(sort).ToList(); return(list); }