title: Push object to a mongoose array and check for duplicate fields inside the array objects
body: <p>I am trying to push a notification object to a mongoDB array with the follow condition:</p>
  
  <p>Check if there is a notification inside the array with the same postId 
  <strong>If yes:</strong> return that object
  <strong>If no:</strong> create a new notification object</p>
  
  <p>I'm using node with Mongoose ODM. In some other questions online they give this as an answer: </p>
  
  <pre><code>user.update({'notifications.postId': {$ne: post._id}}, {$push: { 'notifications': {type: 'POST', postId: post._id}}}, function(err, doc) {
    .....
  });
  </code></pre>
  
  <p>But this didn't work for me.</p>
  
  <p>Below you find the structure of the mongodb document.</p>
  
  <pre><code>{
      "_id": {
          "$oid": "56631b22067ee41847dab6bb"
      },
      "unreadNotifications": 0,
      "notifications": [
        {
          "type": "POST",
          "postId": {
            "$oid": "5666b78b61eb95bc03d47a71"
          },
          "_id": {
            "$oid": "56782daa395840efd4ed3f7a"
          },
          "createdAt": {
            "$date": "2015-12-21T16:49:46.903Z"
          },
          "events": []
        }    
      ]
      "created": {
          "$date": "2015-12-05T17:13:06.782Z"
      },
      "lastName": "Power",
      "firstName": "John",
      "__v": 0
  }
  </code></pre>