Chapter 3 , $group and accumulators

Hi guys ,

I have created an array awards after spliting the initial string. Now I want to keep only one of the values/strings after the split.

But I don’t know how which method I can use to keep only the value equal to " Won x Oscars". I have searched the documentation but haven’t found what I’am looking for yet.

I also dont understand why it wont project the title after grouping the movies by awards…

Please post your aggregation pipeline as text versus a screenshot. This way we can see all of it and paste it in our environment to test.

After $group there is not title field anymore. Only grouped fields are passed to next stage. See


Hi @steevej,

I believe my query it’s correct , but the values don’t match the options ( standarDeviation and average) :, i have 910 documents that match :

db.movies.aggregate([ {$match : {"awards" : /Won . Oscar*/gi }} , {$group : { "_id": null, 'highestR':{$max: '$imdb.rating'}, 'lowestR': {$min: '$imdb.rating'}, 'averageR': {$avg: '$imdb.rating'}, 'standardDeviation': {$stdDevPop: '$imdb.rating'}    }} ]).pretty()

there is a problem with your regex
. match only one character so you don’t catch for example things like “Won 10 Oscars”

In addition you should use the sample standard deviation expression instead of the population standard deviation.

1 Like

Oh , I see ! Only matches 1 to 9.

Thanks !

1 Like