Lab 3.3 Using $lookup

Two questions:

When checking a route to see if it uses a 380 or 747, should we split the string to see if 747 is contained in the string OR simply make sure the string is just 380 or 747?

Is KLM Royal Dutch Airlines the same as KLM?

KLM is listed in the SkyTeam air alliance. All other airlines are listed by their full name. It seems to me that air alliance entry for KLM should be KLM Royal Dutch Airlines.

See the example below for KLM Royal Dutch Airlines.

// db.air_routes.findOne({'airline.name': 'KLM Royal Dutch Airlines'})
{
"_id" : ObjectId("56e9b39c732b6122f87887d4"),
"airline" : {
	"id" : 3090,
	"name" : "KLM Royal Dutch Airlines",
	"alias" : "KL",
	"iata" : "KLM"
},
"src_airport" : "AMS",
"dst_airport" : "LYS",
"codeshare" : "Y",
"stops" : 0,
"airplane" : "EMJ F70"
}

You can use a regular expression to get the airplanes containing ‘380’ or ‘747’.

Not really. That would match for example 93809 unless you make your regex kind of complicated.

I think it is easiest to split the string on blanks.

But that does not answer my question. Are we supposed to include

airplane: '380 E57'

or just

airplane: '380'

Rob

@robkat

Well, a quick check shows that if a route has multiple plane types, they’re string values separated by a space. So you want to see if the desired value is in the string, not that the string only is the desired value.

And, no, KLM Royal Dutch Airlines is not (for our purposes) the same as KLM. In this case, you have to take the data as given, not as you think it should be. In the real world, this would be an issue of course, as they are in fact the same, but for our purposes here, it isn’t relevant and won’t change the correct answer. HTH.

@robkat

Given the actual data schema here, a regex is a perfectly good way to solve the problem. Although a general case such as you point out would be confusing, the actual data consists of simple strings of the aircraft type, all of which will resolve in a regex. So either approach should work just fine here. The split is the more general approach, but probably requires more work than the regex.