-1

I wanted to get the exact count of Counties.Properties which is in my case is 3 , I tried $size aggregation but didn't get me the desired answer answer .

{ 
"_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"
        }
    ]
},

1 Answers1

0
db.collection.aggregate(

    // Pipeline
    [
        // Stage 1
        {
            $project: {
                count: {
                    $size: '$Countries.Properties'
                },
                "Version": 1,
                "FileNo": 1,
                "Feature": 1,
                "TVProperties": 1,
                "Name": 1,
                "Countries": 1

            }
        },

    ]


);
Rubin Porwal
  • 3,736
  • 1
  • 23
  • 26