Lab - $group and Accumulators ...additional pipeline steps required (?)

The answer to this lab was what I tried but had problems on my client, specifically I got null results. For whatever reason, to get this to work I had to insert a $project step after the $match

“rating”:"$imdb.rating"

and then the $group with $rating instead of $imbd.rating worked fine.

Would this indicate a bug with the client app?

What client are you referring to? mongo shell, a driver, Compass or Atlas?

Null result typically happens when the wrong db/collection is referenced or the pipeline is too restrictive.

C driver

As stated the pipeline works only if I add the projection in between the $match and $group stages

That’s a weird behaviour. It might be driver specific.
Have you tried using other alternatives? I.e. mongo shell, Compass, Atlas?

i eventually got a valid answer so didnt bother trying it in the shell or compass

I’ve just retested the answer using the shell and it works as expected.

Hi @mikeh1980,

For your reference:

  1. https://docs.mongodb.com/ecosystem/drivers/c/
  2. http://mongoc.org/libmongoc/current/aggregate.html

The example in 2nd link will help you understand the $group operator usage with C driver.

Please let me know, if you have any questions.

Thanks,
Sonali