如何使用C#连接两个表,其中一个表包含MongoDB中另一表的ID列表 - c#

我的数据模式就像下面的例子。我想像通过使用C#,LINQ在MongoDB中进行SQL连接一样,将我的订单和产品表并按订单分组产品详细信息。
如何使用C#连接两个表,其中一个表包含MongoDB中另一表的ID列表 - c#

参考方案

波纹管代码正在使用聚合和查找

public class ProductItemModel
{

    public string Id { get; set; }
    public Product[] Items { get; set; }
}

var _orderCollection = _context.GetCollection<Order>("Orders");
var _productCollection = _context.GetCollection<Product>("Products");

var data = (_orderCollection.Aggregate()
           //.Match(p => p.Id == "10000")
           .Lookup<Order, Product, ProductItemModel>(
                _productCollection,
                x => x.Items,
                x => x.Id,
                x => x.Items)
            ).ToList(); 

Mongo汇总 - javascript

我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …

当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java

我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…

提交表单后显示模式对话框 - php

提交下载文件后,我有一张表格。我要自动而不是自动下载文件..以显示模态对话框并显示下载链接。<form name="softwareform" id="softwareform" action="../downloadlink.php" method="POST" alig…

DataSourceTransactionManager和JndiObjectFactoryBean和JdbcTemplate的用途是什么? - java

以下的用途是什么:org.springframework.jdbc.core.JdbcTemplate org.springframework.jdbc.datasource.DataSourceTransactionManager org.springframework.jndi.JndiObjectFactoryBean <tx:annotatio…

通过ExecutorService执行线程时Thread.join()不起作用 - java

这是我的代码:public static void main(String[] args) { System.out.println("program started"); ExecutorService executor = Executors.newCachedThreadPool(); Thread thread = new Thr…