我有类似于存储在mongodb中的文档
{
"_id":"transaction_id"
"customer":"some customer",
"order_date":Date('2011-01-01'),
"delivery_date":Date('2011-01-15'),
"amt":500.0,
"qty":50
},
{
"_id":"transaction_id"
"customer":"some customer",
"order_date":Date('2011-01-01'),
"delivery_date":Date('2011-02-04'),
"amt":500.0,
"qty":50
}
Run Code Online (Sandbox Code Playgroud)
我希望对订单日期和交货日期进行一些汇总,以绘制每月订购和交付给每个客户的库存总量.
当然,我可以运行2个聚合查询来获得我想要的东西,但我只是想知道是否有可能获得具有2组具有1个命令的结果?
预期结果如下:
results:[{
_id:{
customer:"some customer"
},
orders:[
{
year:2011,
month:1,
qty:100
},
...
]
deliveries:[
{
year:2011,
month:1,
qty:50
},
{
year:2011,
month:2,
qty:50
},
...
]
},...]
Run Code Online (Sandbox Code Playgroud)