我想获得Counties的确切数量。在我的情况下属性是3,我尝试了$ size聚合,但没有得到我想要的答案答案。
{
"_id" : ObjectId("234567890"),
"Version" : "1.1",
"FileNo" : "1234567",
"Feature" : [
"Map",
"usr/ammer"
],
"TVProperties" : [
"foul"
],
"Name" : "nice",
"Countries" : {
"Properties" : [
{
"kyu" : "NAmerica",
"triggerString" : "America",
"user" : "ME"
},
{
"kyu" : "ASIA",
"triggerString" : "China",
"user" : "You"
},
{
"kyu" : "Europe",
"triggerString" : "France",
"user" : "HE"
}
]
},
答案 0 :(得分:0)
db.collection.aggregate(
// Pipeline
[
// Stage 1
{
$project: {
count: {
$size: '$Countries.Properties'
},
"Version": 1,
"FileNo": 1,
"Feature": 1,
"TVProperties": 1,
"Name": 1,
"Countries": 1
}
},
]
);