In docs, it says that $startWith is the value that recursive search starts according to $connectFromField’s equality to it.
But in the video named [ $graphLookup: Cross Collection Lookup], if you set $maxDepth
to 0 for the first query,
db.air_airlines.aggregate([
{ $match: {name: "TAP Portugal"} },
{ $graphLookup: {
from: 'air_routes',
as: 'chain',
startWith: '$base',
connectFromField: 'dst_airport',
connectToField: 'src_airport',
maxDepth: 0
}
}
]).pretty()
you see that result contains
{
"_id" : ObjectId("56e9b39c732b6122f878e40d"),
"airline" : {
"id" : 5265,
"name" : "US Airways",
"alias" : "US",
"iata" : "USA"
},
"src_airport" : "OPO",
"dst_airport" : "MAD",
"codeshare" : "Y",
"stops" : 0,
"airplane" : "ER4"
}
so from what I understand, first comparison is not $connectFromField = $startsWith but it is $connectToField = $startsWith.