我尝试使用 c# mongodb 驱动程序 (MongoDB.Driver.2.0.1) 执行查询,
dbCollection.Aggregate().Match(query).Sort(sort Definition).Skip(startIndex - 1).Limit(count).ToListAsync().Result
Run Code Online (Sandbox Code Playgroud)
它是错误滴: "Command aggregate failed: exception: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in..."
当我添加一个选项 allowDiskUse = true 时,它执行成功
dbCollection.Aggregate(new Aggregated Options{AllowDiskUse=true}).Match(query).Sort(sort Definition).Skip(startIndex - 1).Limit(count).ToListAsync().Result
Run Code Online (Sandbox Code Playgroud)
但是,我想了解,它的查询在服务器上执行吗?因为当我在 robomongo(在服务器上)有限制地执行它的查询时,它不会下降,但是当我无限制地完成这个查询时,它会下降。
我尝试执行此查询:
MongoCollection<AnalyticsClicks> dbCollection = DetermineCollectionName<AnalyticsClicks>();
var query = from c in dbCollection.AsQueryable()
where c.UserId == userId && c.CampaignId == campaignId
select new
{
c.Email,
c.Link
};
var res = query.GroupBy(x => x.Email, b => b.Link).Count();
Run Code Online (Sandbox Code Playgroud)
但我有例外:
不支持GroupBy查询运算符.
我在robomongo写了一个等价的请求
db.analyticsClicks.aggregate(
{ $match: { UserId: 4790, CampaignId: 92093}},
{ $group : {
"_id" : {
"Email" : "$Email",
"Link" : "$Link",
}
}
})
Run Code Online (Sandbox Code Playgroud)
它有效,但我还需要获取当前集合中的项目数.如何使用C#mongo驱动程序重写此查询?