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

allow nested $facet in another $facet of aggregate

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Query Optimization

      Like below code:

      db.test.aggregate([
        {
          "$facet": {
            "allGroups": [
              {
                "$facet": {
                  "group1": [{
                    "$group":{"_id": "$item1"}
                  }],
                  "group2": [{
                    "$group":{"_id": "$item2"}
                  }]
                }
              }
            ],
            "size": [
              {
                "$count": "size"
              }
            ]
          }
        }
      ])
      

      This will thrown:

      "errmsg" : "specified stage is not allowed to be used within a $facet stage: 0: { $facet: { group1: [ { $group:

      Unknown macro: { _id}

      } ], group2: [ { $group:

      Unknown macro: { _id}

      } ] } }",
      "code" : 40331,
      "codeName" : "Location40331"

      Hope to allow nested $facet happen, is there any downside?

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            futurist Jame Yang
            Votes:
            7 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated: