title: How to Update Multiple Array Elements in mongodb
body: <p>I have a Mongo document which holds an array of elements.</p>
  
  <p>I'd like to reset the <code>.handled</code> attribute of all objects in the array where <code>.profile</code> = XX.</p>
  
  <p>The document is in the following form: </p>
  
  <pre><code>{
      "_id": ObjectId("4d2d8deff4e6c1d71fc29a07"),
      "user_id": "714638ba-2e08-2168-2b99-00002f3d43c0",
      "events": [{
              "handled": 1,
              "profile": 10,
              "data": "....."
          } {
              "handled": 1,
              "profile": 10,
              "data": "....."
          } {
              "handled": 1,
              "profile": 20,
              "data": "....."
          }
          ...
      ]
  }
  </code></pre>
  
  <p>so, I tried the following:</p>
  
  <pre><code>.update({"events.profile":10},{$set:{"events.$.handled":0}},false,true)
  </code></pre>
  
  <p>However it updates only the <strong>first</strong> matched array element in each document. (That's the defined behaviour for <a href="http://www.mongodb.org/display/DOCS/Updating#Updating-The%24positionaloperator" rel="noreferrer">$ - the positional operator</a>.)</p>
  
  <p>How can I update <strong>all</strong> matched array elements?</p>