Unable to do final $match in Chapter 1 - Optional lab

I came to the aggregation stage, where my documents contain a correctly computed boolean field, which indicates
"lol": true
for each movie that correctly fulfills the condition.

{ "title" : "The Conquest of the Pole", "cast" : [ "Georges M�li�s", "Fernande Albany" ], "directors" : [ "Georges M�li�s" ], "writers" : [ "Georges M�li�s", "Georges M�li�s", "Jules Verne" ], "lol" : [ true, true, false ], "test" : true }

Now, when I add final $match for this field, here’s the stage:

{ "$match": { "test": true } }

I get following error:

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate(pipeline)
2019-10-18T18:07:43.668+0200 E  QUERY    [js] uncaught exception: Error: command failed: {
        "operationTime" : Timestamp(1571414858, 1),
        "ok" : 0,
        "errmsg" : "$in requires an array as a second argument, found: missing",
        "code" : 40081,
        "codeName" : "Location40081",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1571414858, 1),
                "signature" : {
                        "hash" : BinData(0,"VuJ7mqkwDck8Pfalfrsu45HUOBU="),
                        "keyId" : NumberLong("6698341139830800385")
} : aggregate failed :

What’s wrong?


It would seem somewhere in your pipeline that you are not using the $in operator or aggregation expression correctly. Keep in mind there are two versions. One in the query operator version and the other is the aggregation expression version.

FYI $match take the query versions where $project and $addFields take the expression version.

Hi @natac13,

Fairly, this would be the first thing to consider. But my pipeline consists of 4 stages that work perfectly fine. The issue appears only once I add the final $match stage

Strangely, the whole pipeline works in auto preview in Compass (see image below).

And even more weirdly, once I increase the sample size from 20 to 200, it fails also there (see another image below).

This must be either:

  • a resource issue or
  • a data issue