Can anyone tell me where i am wrong Expected answer is 15 but i am getting 18 as from sample collection

I am using below pipeline

[
    {
        '$match': {
            'imdb.rating': {
                '$gte': 7
            }, 
            'genres': {
                '$nin': [
                    'Crime', 'Horror'
                ]
            }, 
            'rated': {
                '$in': [
                    'PG', 'G'
                ]
            }, 
            'languages': {
                '$all': [
                    'English', 'Japanese'
                ]
            }
        }
    }, {
        '$count': 'total'
    }
]

It is my understanding that the pipeline is supposed to return 23 documents. Yours return 1 document that is the count. If you look at the instructions they write

You can verify this by typing db.movies.aggregate(pipeline).itcount()

This seems to imply that the pipeline should returned the matched document rather than the $count. So I would remove $count and make sure that db.movies.aggregate(pipeline).itcount() returns the number 23.

Then I would run validateLab1 again with the updated pipeline.

1 Like