title: How to $push , $set and $inc together in mongodb?
body: <p>Basically,I am using loopback with mongodb and want to push the data, set the data and increment the data together and get the final result.</p>
  <p>For that i tried this.</p>
  <pre><code>db.invoice.findOneAndUpdate({ _id: ObjectId(req.params.id) },
          {
              $push: { payment: paymentData }
              , $set: { payment_status: true, updated_at: new Date() }
              , $inc: { total_amount_paid: paidAmt }
          }
          ,
          function (err, doc) {
              if (err) { return new Error(err); }
              else {
                  if (doc.result.n&gt;0) {
                      setTimeout(function () { }, 200);
                      console.log(&quot; Invoice updated with Payment info.&quot;);
                      nextCall(null, { code: 200, data: doc.result });
                  } else {
                      console.log(&quot;Something went wrong while payment info updation.&quot;)
                      nextCall(null, { code: 400, status: 'Something went wrong while payment info updation.' })
                  }
              }
          });
      }); 
  </code></pre>
  <p><strong>Case 1 :</strong></p>
  <p>Document is updating but not pushing in payment Array.</p>
  <p><strong>Case 2:</strong></p>
  <p>If I remove the callback function
  it is pushing, setting the value and also incrementing the total amount paid.$inc</p>
  <p>Could someone tell me where I am doing wrong if want to achieve case2 ?</p>
  <p>Thanks</p>