allowDiskUse在聚合框架与MongoDB的C#驱动程序

编程入门 行业动态 更新时间:2024-10-26 15:20:28
本文介绍了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#驱动程序

本文发布于:2023-11-22 09:40:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616925.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:驱动程序   框架   allowDiskUse   MongoDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!