title: correctly grouping documents in aggregate pipeline in order to find setintersection
body: <p>say I have these two documents:</p>
  
  <pre><code>{  
     "_id":"sampleA",
     "value":{  
        "data":[  
           {  
              "thing":"A"
           },
           {  
              "thing":"B"
           },
           {  
              "thing":"C"
           },
           {  
              "thing":"D"
           },
           {  
              "thing":"E"
           }
        ]
     }
  }
  
   {  
     "_id":"sampleB",
     "value":{  
        "data":[  
           {  
              "thing":"C"
           },
           {  
              "thing":"D"
           },
           {  
              "thing":"E"
           },
           {  
              "thing":"F"
           }
        ]
     }
  }
  </code></pre>
  
  <p>and I want to group them into one document, retaining the label of "sampleA" or "sampleB" such as</p>
  
  <pre><code>{
    "_id": null,
    "sampleA": [
      {
        "thing": "A"
      },
      {
        "thing": "B"
      },
      {
        "thing": "C"
      },
      {
        "thing": "D"
      },
      {
        "thing": "E"
      }
    ],
    "sampleB": [
      {
        "thing": "C"
      },
      {
        "thing": "D"
      },
      {
        "thing": "E"
      },
      {
        "thing": "F"
      }
    ]
  }
  </code></pre>
  
  <p>So that way I can use the set intersection operator. How do I go about doing this? I tried:</p>
  
  <pre><code>db.testz.aggregate(
        [{
          $match: {
            _id: {
              $in: ["sampleA", "sampleB"]
            }
          }
        }, {
          '$group': {
            _id: null,
            a: {
              $push: "$value"
            }
          }
        }]
      );
  </code></pre>
  
  <p>which gives me</p>
  
  <pre><code>{
    "_id": null,
    "a": [
      {
        "data": [
          {
            "thing": "A"
          },
          {
            "thing": "B"
          },
          {
            "thing": "C"
          },
          {
            "thing": "D"
          },
          {
            "thing": "E"
          }
        ]
      },
      {
        "data": [
          {
            "thing": "C"
          },
          {
            "thing": "D"
          },
          {
            "thing": "E"
          },
          {
            "thing": "F"
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <p>Presumably I could then use the set intersection operator if I could index the items in a?</p>
  
  <pre><code>    db.testz.aggregate(
        [{
          $match: {
            _id: {
              $in: ["sampleA", "sampleB"]
            }
          }
        }, {
          '$group': {
            _id: null,
            a: {
              $push: "$value"
            }
          }
        }, {
          '$project': {
            int: {
              $setIntersection: ["$a.0", "$a.1"]
            }
          }
        }]
      );
  </code></pre>
  
  <p>^^ obviously this last step here doesn't work, but I am trying to illustrate the point. </p>