我想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#驱动程序
发布评论