MongoDB与C#中的聚合管道查询

时间:2018-06-27 09:24:54

标签: mongodb mongoose aggregation-framework lookup pipeline

要使用MongoDb Aggregate管道,我已经在管道下面创建了该管道。

Mongodb C#管道代码:

PipelineDefinition<Packet, BsonDocument> pipeline = new BsonDocument[]
            {
                new BsonDocument("$match", new BsonDocument()
                        .Add("_id", new BsonDocument()
                                .Add("$in", new BsonArray()
                                        .Add(new BsonObjectId(new ObjectId("5b2e1e3ff29b405cc3987773")))

                                )
                        )),
                new BsonDocument("$lookup", new BsonDocument()
                        .Add("from", "PacketImage")
                        .Add("localField", "_id")
                        .Add("foreignField", "pctiD")
                        .Add("as", "Other"))
            };

并将该管道应用于collection.Aggregate(pipeline)。但这给了我以下结果。我不明白为什么会有两个开头{{和两个结尾}},因为我以为会是一个。

结果: {{ "_id" : ObjectId("5b2e1d94b6d37c5c22ee4820"), "nm" : "AB-3", "v" : NumberLong(1), "cB" : null, "cD" : ISODate("2018-06-23T10:14:44.632Z"), "uB" : null, "uA" : ISODate("2018-06-23T10:14:44.632Z"), "kP" : null, "pN" : null, "sN" : "AB-3", "rfI" : null, "sH" : "MQ", "cO" : "E", "cL" : "VS1", "cT" : "EX", "pL" : "EX", "sY" : "EX", "fL" : "None", "wT" : 4.5999999999999996, "rP" : null, "dS" : null, "nA" : null, "mA" : { "leN" : null, "wiD" : null, "deP" : null, "raT" : null, "tlD" : null, "tlA" : null, "crH" : null, "crA" : null, "pD" : null, "pA" : null, "sL" : null, "lH" : null, "giP" : null, "giC" : null, "gi" : null, "hnA" : false }, "laB" : { "labN" : null, "labI" : null, "cN" : null, "cerN" : null, "resD" : null }, "iN" : { "lB" : null, "gR" : null, "mL" : null, "sB" : null, "cB" : null, "sW" : null, "cW" : null, "opT" : null, "opC" : null, "opP" : null, "opG" : null, "nbL" : null, "bgM" : null, "ktS" : null, "eyC" : null, "culT" : null }, "prC" : { "idetY" : "Employee", "idenT" : "5b2735b7fbe240077c4b3ed9", "itN" : "Harshad B Pansuriya", "isT" : ISODate("2018-06-21T09:38:24.607Z") }, "iiN" : false, "ioH" : null, "iS" : null, "iA" : true, "coM" : null, "Other" : [{ "_id" : ObjectId("5b2e1d94b6d37c5c22ee4822"), "nm" : "ASD", "v" : NumberLong(1), "cB" : null, "cD" : ISODate("2018-06-23T10:14:44.987Z"), "uB" : null, "uA" : ISODate("2018-06-23T10:14:44.987Z"), "pctiD" : ObjectId("5b2e1d94b6d37c5c22ee4820"), "tyP" : "GIA", "exT" : ".jpeg", "urL" : null, "imG" : null, "isD" : false }] }}

任何解释和帮助将不胜感激。

0 个答案:

没有答案