Tag: aggregation framework

使用MongoDB C#驱动程序在Aggregation Framework中使用allowDiskUse

我想允许DiskUse:true。 但是,我找不到任何解释allowDiskUse启用MongoDB C#驱动程序的示例。 如何在MongoDB C#驱动程序中启用allowDiskUse? 我的示例代码就是这样 var pipeline = new[] { match, project, group, limit, sort, allow }; List result = db .GetCollection(“TwitterStatus”) .Aggregate(pipeline).ResultDocuments.Select(x => new User { Influence = Convert.ToDouble(x[“Influence”]), User = new SMBUser((BsonDocument)x[“User”]) }).ToList();

在聚合框架中使用Facets C#with Multiple Facet,Unwind和sortByCount

如何在C#中表示此管道? —–Id —–Name —–ProductAttributes (object array) | —–ProductAttributeType —–ProductAttributeValues (string array) 我的collections: { “_id” : ObjectId(“5b41a5e225cd892c14628b78”), “Name” : “Esmalte Super Pérola Fashion Glamour”, “ProductAttributes” : [ { “ProductAttributeType” : “Coleção”, “Values” : [ “Fashion” ] }, { “ProductAttributeType” : “Tamanho”, “Values” : [ “8 ml” ] }, { “ProductAttributeType” : “Tom”, “Values” : [ “Vermelho”, […]

使用C#聚合$ lookup

我有以下MongoDb查询工作: db.Entity.aggregate( [ { “$match”:{“Id”: “12345”} }, { “$lookup”: { “from”: “OtherCollection”, “localField”: “otherCollectionId”, “foreignField”: “Id”, “as”: “ent” } }, { “$project”: { “Name”: 1, “Date”: 1, “OtherObject”: { “$arrayElemAt”: [ “$ent”, 0 ] } } }, { “$sort”: { “OtherObject.Profile.Name”: 1 } } ] ) 这将检索与另一个集合中的匹配对象连接的对象列表。 有没有人知道如何使用LINQ或使用这个确切的字符串在C#中使用它? 我尝试使用以下代码,但它似乎无法找到QueryDocument和MongoCursor的类型 – 我认为它们已被弃用? BsonDocument document = MongoDB.Bson.Serialization.BsonSerializer.Deserialize(“{ […]

如何在MongoDB中的文档内聚合数组并获取多个条件的计数?

我正在编写一个程序,该程序接收车辆刷新数据的XML文件并将其转换为JSON,以便将其存储在MongoDB数据库中。 XML的开头是这样的: PASSED PASSED 在我将其转换为JSON并添加项目标识符之后,我留下了一个像这样的格式: { “FlashReportGeneratorAddedTag” : { “VehicleEntry” : [ { “VehicleStatus” : “PASSED” }, { “VehicleStatus” : “PASSED” } ] }, “project_id” : “1234” } 我想做的是获得项目1234的每个文件中通过的车辆总数和车辆数量的总数,但我没有运气。 我已经尝试过使用我所知道的基本聚合技能,但我不能简单地按project_id进行分组,因为当我需要聚合其中的数组时,它会按文档分组。 我还没有找到任何资源告诉你是否可以或不能一次聚合两个值(获得传递的总和和失败计数的总和)。 作为最后的手段,我可​​以改变文档样式,让每个VehicleEntry都是它自己的文档,但是如果可以的话,我想采用并存储XML。 编辑使用Unwind我能够为我正在寻找的数组设置聚合: var aggregate = collection.Aggregate().Match(new BsonDocument { { “project_id”, “1234” } }).Unwind(i => i[“FlashReportGeneratorAddedTag.VehicleEntry”]); 但是,我找不到合适的方法对这些进行分组,以便在整个arrays中获得通过/失败计数。 我假设有一些方法我需要使用匹配function,但我不知道如何做到这一点,而不排除这两个条件之一。 我是否必须运行聚合两次,一次是传递,一次是失败?