Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 0.40 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. MongoDB: Updating multiple using '$in'
  2. db.users.update({userid: {$in: ['1','2','3']}}, {$inc: {mycounter: 1}}, false, true);
  3.        
  4. for(var i = 0; i < 100000; i++) { db.foo.save({ _id : i, x : 1 }) }
  5. db.foo.count(); // should be 100k
  6.  
  7. query = []
  8. for(var i = 0; i < 10000; i++) { query.push(i) }
  9. db.foo.update( { _id : {$in:query} }, {$inc : {x:1} }, false, true)
  10.  
  11. db.foo.find({x:2}).count()  // should be 10k