title: How to apply $arrayToObject to the array output by $push in mongodb aggreggation
body: <p>The code below (with the two lines commented out)</p>
  
  <pre><code>    myComments.aggregate(
          { $sort: { createdAt: -1 } },
          { $match: query },
          { $group: {
              _id: {
                  activity: "$activity",
                  writer: "$writer"
              },
              summary: {
                  // $arrayToObject: {
                      $push: {
                          "k": "$userID",
                          "v": "$commentText",
                      }
                  // }
              },
          } },
          { $project: { _id: 0 } },
          ( err, data ) =&gt; {
              console.log( JSON.stringify( data || [] ) );
          }
      )
  </code></pre>
  
  <p>produces "summary" arrays as expected:</p>
  
  <pre><code>    [ {"summary":[ {"k":183044,"v":"adf"}, {"k":184817,"v":"be"}, {"k":187252,"v":"c"} ]},
        {"summary":[ {"k":183044,"v":"146"}, {"k":184817,"v":"25"}, {"k":187252,"v":"3"} ]} ]
  </code></pre>
  
  <p>However, when I remove the comments and allow <code>$arrayToObject</code> to act upon those arrays the output <code>data</code> is undefined.</p>
  
  <p>Am I using one or both of these commands incorrectly? Is it incorrect to nest them this way? </p>