我有两个集合的一对多关系,比如 A 到 B。我怎样才能在一个文档中为每个 id 显示所需的输出。例如,我有
/*Collection A*/
{
"a_Id": "abc",
"name": "xyz",
"age": 5
}
...//其他文档
/*Collection B*/
{
"b_id": "abc",
"FeeAmount": 800000,
"invoiceNumber": "A10",
"Date": "2021-10-29T00:00:00.000+04:00",
"PaidAmount": 200000
},
{
"b_id": "abc",
"FeeAmount": 90,
"invoiceNumber": "A20",
"Date": "2021-10-29T00:00:00.000+04:00",
"PaidAmount": 20
}
//...其他文档为不同的ID,例如abc1,abc2
基于 id 查找后如何实现以下输出?这是每个 id 一个文档。
/*Desired OutPut*/
//Document 1
{
"name": "xyz",
"age": 5
"availableLimitAmount": 800000,
"FeeAmount": 800000,
"invoiceNumber": "A10",
"Date": "2021-10-29T00:00:00.000+04:00",
"PaidAmount": 200000
},
{
"name": "xyz",
"age": 5
"FeeAmount": 90,
"invoiceNumber": "A20",
"Date": "2021-10-29T00:00:00.000+04:00",
"PaidAmount": 20
}
//Document 2
{
"name": "qwe",
"age": 50
"availableLimitAmount": 20000,
"FeeAmount": 40000,
"invoiceNumber": "B10",
"Date": "2021-1-1T00:00:00.000+04:00",
"PaidAmount": 1000
},
{
"name": "qwe",
"age": 50
"FeeAmount": 40,
"invoiceNumber": "B20",
"Date": "2021-2-2T00:00:00.000+04:00",
"PaidAmount": 500
}