如何使用MongoDB C#驱动程序进行$ lookup? [英] How to $lookup with MongoDB C# driver?

查看:411
本文介绍了如何使用MongoDB C#驱动程序进行$ lookup?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用MongoDB C#驱动程序执行$ ​​lookup?我在这里的驱动程序文档中找不到它:

How do I perform a $lookup with the MongoDB C# driver? I cannot find it in their driver doc here:

https://docs.mongodb.org/getting-started/csharp/query /

但是,如果我在他们的JIRA中正确理解了该票证,则该票证应为驱动程序的2.2版本:

But if I understand this ticket in their JIRA correctly, it should be in the 2.2 version of the driver:

https://jira.mongodb.org/browse/CSHARP-1374

推荐答案

如果在IMongoCollection< T>上使用AsQueryable()扩展方法,则可以使用LINQ接口作为示例.

If you use the AsQueryable() extension method on IMongoCollection<T>, you can then use the LINQ interface, as an example.

var query = from p in collection.AsQueryable()
            join o in otherCollection on p.Name equals o.Key into joined
            select new { p.Name, AgeSum: joined.Sum(x => x.Age) };

这是从mongodb csharp驱动程序文档中复制的,这里

This was copied from the mongodb csharp driver documentation here http://mongodb.github.io/mongo-csharp-driver/2.2/reference/driver/crud/linq/#lookup

这篇关于如何使用MongoDB C#驱动程序进行$ lookup?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆