我有2个集合客户和订单,样本数据如下
**Customers**
{ "_id" : 1, "name" : "John", "sex" : "male" }
{ "_id" : 2, "name" : "Sara", "sex" : "female"}
{ "_id" : 3, "name" : "Jack", "sex" : "male"}
{ "_id" : 4, "name" : "David", "sex" : "male"}
**Orders**
{ "_id" : 1, customerId: 1 }
{ "_id" : 2, customerId: 1 }
{ "_id" : 3, customerId: 2 }
我想:
- 仅计算订购客户的总数
- 计算总男性或女性
使用mongo聚合
谢谢!