0
0
MongoDBquery~10 mins

Graph lookup for recursive data in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a $graphLookup stage in an aggregation pipeline.

MongoDB
{ $graphLookup: { from: "employees", startWith: "$managerId", connectFromField: "[1]", connectToField: "_id", as: "reportingHierarchy" } }
Drag options to blanks, or click blank then click option'
Asubordinates
BemployeeId
CreportsTo
DmanagerId
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong field that does not reference the manager.
Confusing connectFromField with connectToField.
2fill in blank
medium

Complete the code to specify the field to match in the $graphLookup stage.

MongoDB
{ $graphLookup: { from: "employees", startWith: "$managerId", connectFromField: "managerId", connectToField: "[1]", as: "reportingHierarchy" } }
Drag options to blanks, or click blank then click option'
AmanagerId
B_id
CemployeeId
DreportsTo
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-unique field for connectToField.
Mixing up connectFromField and connectToField.
3fill in blank
hard

Fix the error in the $graphLookup stage by completing the missing field.

MongoDB
{ $graphLookup: { from: "employees", startWith: "$managerId", connectFromField: "managerId", connectToField: "_id", as: "[1]" } }
Drag options to blanks, or click blank then click option'
AreportingHierarchy
Bsubordinates
Cmanagers
DteamMembers
Attempts:
3 left
💡 Hint
Common Mistakes
Using a vague or unrelated field name.
Leaving the as field empty or incorrect.
4fill in blank
hard

Fill both blanks to complete the $graphLookup stage that limits recursion depth and filters results.

MongoDB
{ $graphLookup: { from: "employees", startWith: "$managerId", connectFromField: "[1]", connectToField: "[2]", as: "team" , maxDepth: 2 } }
Drag options to blanks, or click blank then click option'
AmanagerId
B_id
CemployeeId
DreportsTo
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the two fields.
Using unrelated field names.
5fill in blank
hard

Fill all three blanks to create a $graphLookup stage that starts from a specific employee, connects fields correctly, and stores results.

MongoDB
{ $graphLookup: { from: "employees", startWith: "[1]", connectFromField: "[2]", connectToField: "[3]", as: "allReports" } }
Drag options to blanks, or click blank then click option'
A"$employeeId"
BmanagerId
C_id
D"$managerId"
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes and $ in startWith.
Mixing up connectFromField and connectToField.