Why is there a $ prefix in the startWidth argument but not the connectToField or connectFromField arguments?

    {$match: {name: "Shannon"}},
    { $graphLookup: {
      from: "parent_reference",
      startWith: "$reports_to",
      connectFromField: "reports_to",
      connectToField: "_id",
      as: "bosses" }

All of those arguments are referencing field names, so why only startWith value is prefixed with a $?

If you look at the $graphLookup documentation you will see that startWith is defined as <expression>. In an expression, when you want the value of a field, rather than the field name, you prefix it with $. If you don’t the expression is the field name.

As for connectFromField and connectToField they are defined as <string> and must be field name as per documentation.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.