我有一个简单的集合,其中包含如下所示的供应商文档:
{
"name": "Nick's Burger",
"country": "AT",
"branches": [
{
"branchId": "12535",
"branchName": "Nick's Burger Branch One",
"branchAddress": "Somewhere in austria"
},
{
"branchId": "38267",
"branchName": "Nick's Burger Branch Two",
"branchAddress": "Somewhere else in austria"
}
]
}
每个供应商都有一个“分支机构”列表,我想计算“ {country} AT
个国家/地区的所有供应商有多少个分支机构。
尝试了以下内容:
db.vendors.find({country: "AT"}, {$size: {branches: 1}}).count()
但这只给了我来自AT的供应商数量...