title: MongoDB project into an array
body: <p>I have array of objects (nested), and I want to pull a couple of the elements from those nested objects, and return these fields in an array. Below is my document structure (mocked it from original data)</p>
  
  <pre><code>"detailLine": [
      {
          "name": "first",
          "value": {
              "lineNumber": 1,
              "subLineCode": " ",
              "detailLineCharges": {
                  "allowedAmount": {
                      "amount": "11111",
                      "reasonCode": “aaaah”
                  }
              }
          }
      },
      {
          "name": "first",
          "value": {
              "detailLineCharges": {
                  "allowedAmount": {
                      "amount": "22222",
                      "reasonCode": “BBBB”
                  }
              }
          }
      }
  ]
  </code></pre>
  
  <p>I would like to see my results something like this</p>
  
  <pre><code>details: [
    {
      amount:”11111”,
      reasonCode : “aaaah”
    },
    {
      amount : “22222”,
      reasonCode : “BBBB”
    }
  ]
  </code></pre>
  
  <p>I tried </p>
  
  <pre><code> db.collection.aggregate([
     {
       $match: {
         _id: "123456"
       }
     }, 
     {
       $project: {
         details: {
           $push {
             amount: "$detailLine.value.detailLineCharges.allowedAmount.amount",
             reasoncode: "$detailLine.value.detailLineCharges.allowedAmount.reasonCode"
           }
         }
       }
     }
  ])
  </code></pre>
  
  <p>but I am getting this error</p>
  
  <pre><code>Error: command failed: { "ok" : 0, "errmsg" : "invalid operator '$push'", "code" : 15999 } : aggregate failed :
  </code></pre>
  
  <p>I want to use <code>$project</code> because I am using it to pull too many other fields so that is why I did not try <code>$group</code> for this one particular scenario. </p>
  
  <p>Can anyone help how to get those two fields in an Array?</p>