Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-34064

$graphLookup not starting from collection

    • Type: Icon: Question Question
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.4.14, 3.6.3
    • Component/s: None
    • Labels:
      None
    • Query Optimization

      Just got acquainted with the $graphLookup aggregation, but it seems a little clunky for my main use case. So I have a combined question and/or feature request:

      My use case is I want to fetch all descendants for a node in a tree structure. But I want them as plain documents. Thus I'm forced to something like:

      db.nodes.aggregate([
              {$match: {_id: 'STARTID'}},
              {
                  $graphLookup: {
                      from: 'nodes',
                      startWith: '$_id',
                      connectFromField: 'children',
                      connectToField: '_id',
                      as: 'descendants',
                  },
              },
              {$unwind: '$descendants'},
              {$replaceRoot: {newRoot: '$descendants'}}
          ])
      

      It would be much more natural to me if the $graphLookup operator could operate without a starting collection, i.e. something like (I know this doesn't work now):

      db.aggregate([
              {
                  $graphLookup: {
                      from: 'nodes',
                      startWith: 'STARTID',
                      connectFromField: 'children',
                      connectToField: '_id'
                  },
              }
          ])
      

      So, is this something that can be done today in some similar fashion. Otherwise, it'd be nice to have.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            staffan.eketorp@gmail.com Staffan Eketorp
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: