MongoDB:如何只找到订购的客户?

时间:2018-01-25 04:42:15

标签: mongodb aggregate

我有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聚合

谢谢!

0 个答案:

没有答案