相关疑难解决方法(0)

使用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
            } 
        }
    ]
)
Run Code Online (Sandbox Code Playgroud)

这将检索与另一个集合中的匹配对象连接的对象列表.

有没有人知道如何使用LINQ或使用这个确切的字符串在C#中使用它?

我尝试使用以下代码,但它似乎无法找到类型QueryDocumentMongoCursor- 我认为它们已被弃用?

BsonDocument document = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>("{ name : value }");
QueryDocument queryDoc = new QueryDocument(document);
MongoCursor toReturn = _connectionCollection.Find(queryDoc);
Run Code Online (Sandbox Code Playgroud)

c# mongodb aggregation-framework mongodb-.net-driver

12
推荐指数
1
解决办法
6107
查看次数