Good afternoon,
Q1. So, I had a little time so I thought I would ask, why in $graphLookup the connectFromField and ToField, are meant to be referenced without preceeding a $
$graphLookup: {
from: 'child_reference',
startWith: '$direct_reports',
connectFromField: 'direct_reports',
connectToField: 'name',
as: 'upto_level_2_reports',
maxDepth: 1,
depthField: 'level'
}
Obviously my understanding is limited, but in other stages we reference pre existing fields with a $, apart from the match stage, unless using the $expr.
I just wondered what bit of logic I was missing, or is this one of those “Exceptions”?
Q2. So the output from the $graphLookup, via the as: seems a little random, so I assume that the normal process would be to $unwind the results, and use the depth field to put a bit of structure to the documents?
Is there a way to actually get the output in the such that children documents were within the parent document?