$in vs regex for string comparison in match


I just attempted the aggregation Lab on $lookup - * Which alliance from air_alliances flies the most routes with either a Boeing 747 or an Airbus A380 (abbreviated 747 and 380 in air_routes)?*

Something really puzzled me in the answer when we have to match the records for airplane types.

I am getting different results when I use the $match in the pipeline with $in or a regex, whys that?

{$match: {“routes.airplane”: /747|380/}},


{$match: {“routes.airplane”: {$in:[“747”, “380”]}}},

The array operator $in means strict equality between a field and the values specified. For example, the above $in query will only match documents with

1. airplane:"747",
2. airplane:"380",
3. airplane:["747",... other values] and
4. airplane:["380",... other values]

while the query with the regular expression /747|380/ will match any string that contains the substring 747 or the substring 380. In particular it will match with airplane:"M11 333 747 74M 332" which will not be matched with the $in above. Refer to documentation for further details.