小编Ver*_*nko的帖子

C# mongodb 驱动命令聚合失败排序超出了 104857600 字节的内存限制

我尝试使用 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(在服务器上)有限制地执行它的查询时,它不会下降,但是当我无限制地完成这个查询时,它会下降。

c# mongodb aggregation-framework

5
推荐指数
0
解决办法
1479
查看次数

c#mongodb driver groupby

我尝试执行此查询:

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驱动程序重写此查询?

c# mongodb mongodb-.net-driver

3
推荐指数
2
解决办法
1万
查看次数