title: mongodb increment if exists otherwise insert
body: <p>In the code below i want to insert a value if an itemId and timestamp doesn't exist otherwise if it already exists I want to increment it </p>
  
  <pre><code>Collection.update({
                  itemId: itemId,
                  timestamp: moment.unix(timestamp).set('seconds', 0).toDate(),
              },
              {
                  '$inc': {
                      'data.ph1': data.ph1,
                      'data.ph2': data.ph2,
                      'data.ph3': data.ph3,
                      'data.total': data.total
                  },
              },
              { upsert: true },
              (err,resp) =&gt; {
                  if(err) {
                      reject(err);
                  } else {  
                      resolve('minute value incremented' + gatewayId );
                  }
              });
  </code></pre>
  
  <p>It ends up creating multiple documents instead. Thank you in advance.</p>