title: MongoDB: Update property of subarray just updates the first element
body: <p>The matching element looks like that:</p>
  
  <pre><code>{
      "_id": {
          "$oid": "519ebd1cef1fce06f90e3157"
      },
      "from": "Tester2",
      "to": "Tester",
      "messages": [
          {
              "username": "Tester2",
              "message": "heeey",
              "read": false
          },
          {
              "username": "Tester",
              "message": "hi!",
              "read": false
          },
          {
              "username": "Tester2",
              "message": "test",
              "read": false
          }
      ],
  }
  </code></pre>
  
  <p>Now I try to set the <code>read</code> property to the current date just of the subelements where the username is not equal to <code>Tester</code>:</p>
  
  <pre><code>var messages = db.collection('messages');
  messages.update(
  {
      _id: new BSON.ObjectID("519ebd1cef1fce06f90e3157"),
      messages: {
          $elemMatch: { username: { $ne: "Tester" } }
      }
  },
  { $set: { 'messages.$.read': new Date() } },
  { multi: true }, function(error, result) {
      console.log(error);
      console.log(result);
  });
  </code></pre>
  
  <p>But just the first messages subelement <code>read</code> property updates:</p>
  
  <pre><code>{
      "_id": {
          "$oid": "519ebd1cef1fce06f90e3157"
      },
      "from": "Tester2",
      "to": "Tester",
      "messages": [
          {
              "username": "Tester2",
              "message": "heeey",
              "read":  {
                  "$date": "2013-01-01T00:00:00.000Z"
              }
          },
          {
              "username": "Tester",
              "message": "hi!",
              "read": false
          },
          {
              "username": "Tester2",
              "message": "test",
              "read": false
          }
      ],
  }
  </code></pre>
  
  <p>What's wrong with the code?
  I'm using node.js v0.10.8 and MongoDB v2.4.3 together with <a href="https://github.com/mongodb/node-mongodb-native" rel="nofollow">node-mongodb-native</a>.</p>