title: Mongo bulk find and update matched documents field in single query?
body: <p>I have an image gallery with meta stored in mongo. Every time the web site query matches some number of stored images i would like the documents <code>shown</code> counter field to be incremented. Using <code>findAndModify</code> would work OK for single document but i can't see a nice way to match multiple documents and update them all. </p>
  
  <p>Is this possible with latest version of mongo? Or any recommend best practices to achieve this ?</p>
  
  <p>thanks
  fLo</p>
  
  <p>The document format is very simple</p>
  
  <pre><code>{
  "name"         : "img name",
  "description"  : "some more info",
  "size"         : "img size in bytes",
  "shown"        : "count of times the image was selected by query",
  "viewed"       : "count of times the image was clicked"
  }
  </code></pre>
  
  <p>And the query is a simple find, then use cursor to loop over results and bump the shown count using document id.. i.e.</p>
  
  <pre><code>db.images.update(
     { _id: "xxxx" },
     { $inc: { shown: 1 } }
  )
  </code></pre>
  
  <p>But i would prefer not to get 100 documents then have to loop over each to update individually. Was hoping to perform find and update in single query.</p>