#region 排序获取集合 static List<BsonDocument> GetPagerWithGroup(string connectionString, string databaseName, string collectionName, IMongoQuery param, GroupByBuilder groupByBuilder, PageInfo info, out int pageCount)
/// <summary>
///分组查询获取集合
/// </summary>
/// <param name="connectionString">数据库连接字符串</param>
/// <param name="databaseName">数据库名称</param>
/// <param name="collectionName">集合名称</param>
/// <param name="param">条件</param>
/// <param name="groupByBuilder">分组条件</param>
/// <param name="info">分页信息</param>
/// <param name="pageCount">总页数</param>
/// <returns>List</returns>
public static List<BsonDocument> GetPagerWithGroup(string connectionString, string databaseName,
string collectionName, IMongoQuery param, GroupByBuilder groupByBuilder, PageInfo info, out int pageCount)
{
var collection = GetMongoCollection<BsonDocument>(connectionString, databaseName, collectionName);
var dictionary = new Dictionary<string, int>();
dictionary["num"] = ;
List<BsonDocument> list = null;
var q = collection.Group(param, groupByBuilder, BsonDocument.Create(dictionary),
BsonJavaScript.Create("function(doc,prev){prev.num++;}"),
BsonJavaScript.Create("function(doc){ doc.count=doc.num;delete doc.num; }"));
pageCount = ;
if (info == null)
{
list = q.ToList();
}
else
{
list = q
.Skip((info.PageIndex - ) * info.PageSize).Take(info.PageSize).ToList();
var count = q.Count();
if (count <= )
{
pageCount = ;
return null;
}
pageCount = (int)(count % info.PageSize == ? count / info.PageSize : (count / info.PageSize) + );
}
return list;
}
#endregion