$graphLookup connectFromField connectToField clarification

Hi all, I had a question about the connectToField and connectFromField fields.

Using the first option in the lab I would like to clarify what is happening.

The option contains

db.air_alliances.aggregate([
{
$match: { name: “OneWorld” }
},
{
$graphLookup: {
startWith: “$airlines”,
from: “air_airlines”,
connectFromField: “name”,
connectToField: “name”,
as: “airlines”,
maxDepth: 0,
restrictSearchWithMatch: {
country: { $in: [“Germany”, “Spain”, “Canada”] }
}
}
},

For the most part it makes sense. We are iterating through the OneWorld alliance’s airlines array and matching it to the “connectFromField” which is “names”. What I do not understand is what happens after that. The “connectToField” is also “names”. Does it attempt to do a further match on the "connectFromField"s values to other airlines with the same name. In this case, the value is a single name and not an array and there are no matches found so no recursion occurs? If “connectFromField” and “connectToField” are both arrays, does it do a comparison of all elements to find any match, and if a match is found, it examine’'s that document’s “connectFromField”?

Thank you!

Hi @Jason_79826,

It’s against forum guidelines to discuss specifics around lab/exam answers.

I’d suggest that you review all the $graphLookup lectures again and in addition, go through the $graphLookup documentation… it does a good job of describing what you’re after with a few more examples too.

If you still need further assistance, let us know.

2 Likes