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

$graphLookup not starting from collection

    XMLWordPrintableJSON

Details

    • Icon: Question Question
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • 3.4.14, 3.6.3
    • None
    • None
    • Query Optimization

    Description

      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.

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            staffan.eketorp@gmail.com Staffan Eketorp
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated: