allowDiskUse在聚合框架与MongoDB的C#驱动程序 [英] allowDiskUse in Aggregation Framework with MongoDB C# Driver

查看:2276
本文介绍了allowDiskUse在聚合框架与MongoDB的C#驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想allowDiskUse:真。不过,我也没有找到哪个解释allowDiskUse使MongoDB的C#驱动程序的任何实例。



如何在MongoDB中C#驱动程序中启用allowDiskUse?



就像我的示例代码

  VAR管道=新[] {匹配,项目组的限制,排序,允许}; 

名单,LT; SMBMostInfluentialUser>结果= DB
.GetCollection< SMBTwitterStatus>(TwitterStatus)
.Aggregate(管道).ResultDocuments.Select(X =>
新用户
{
影响= Convert.ToDouble(X [影响力]),
的用户=新SMBUser((BsonDocument)×[用户])
})了ToList()。


解决方案

使用聚合的其他重载需要一个AggregateArgs参数并为您提供更多的控制操作,包括设置AllowDiskUse:

  VAR管道=新BsonDocument [0]; //一个真正的管道
变种aggregateArgs =新AggregateArgs {AllowDiskUse = TRUE,管道=管道}代替;
VAR aggregateResult = collection.Aggregate(aggregateArgs);
变种的用户= aggregateResult.Select(X =方式>
新用户
{
的影响= X [影响] ToDouble(),
的用户=新SMBUser(X [用户] AsBsonDocument。)
})了ToList()。

请注意,这种超负荷骨料的返回类型为IEnumerable的< BsonDocument>让您不再需要使用ResultDocuments属性。



只是要清楚,选择正在执行的客户端。这样出来的聚集管道的文件可以直接反序列化到您的类之一的情况下,您也许能安排。


I would like to allowDiskUse:true. However I could not found any example which explain allowDiskUse enabling for MongoDB C# driver.

How can I enable allowDiskUse in MongoDB C# driver?

My sample code like that

    var pipeline = new[] { match, project, group, limit, sort, allow };

    List<SMBMostInfluentialUser> result = db
        .GetCollection<SMBTwitterStatus>("TwitterStatus")
        .Aggregate(pipeline).ResultDocuments.Select(x =>
            new User
        {
            Influence = Convert.ToDouble(x["Influence"]),
            User = new SMBUser((BsonDocument)x["User"])
        }).ToList();

解决方案

Use the other overload of Aggregate that takes an AggregateArgs parameter and gives you more control over the operation, including setting AllowDiskUse:

var pipeline = new BsonDocument[0]; // replace with a real pipeline
var aggregateArgs = new AggregateArgs { AllowDiskUse = true, Pipeline = pipeline };
var aggregateResult = collection.Aggregate(aggregateArgs);
var users = aggregateResult.Select(x =>
    new User
    {
        Influence = x["Influence"].ToDouble(),
        User = new SMBUser(x["user"].AsBsonDocument)
    }).ToList();

Note that the return type of this overload of Aggregate is IEnumerable<BsonDocument> so you no longer have to use the ResultDocuments property.

Just to be clear, the Select is being executed client side. You might be able to arrange it so that the documents coming out of your aggregation pipeline can be directly deserialized into instances of one of your classes.

这篇关于allowDiskUse在聚合框架与MongoDB的C#驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆