Skip to content

Instantly share code, notes, and snippets.

@esedor
Created November 11, 2011 00:03
Show Gist options
  • Save esedor/1356691 to your computer and use it in GitHub Desktop.
Save esedor/1356691 to your computer and use it in GitHub Desktop.
Querying MongoDB in Ruby
col = db.collection('items')
col.insert({'name' => 'sword', 'size' => 3, 'cost' => 4})
col.find({'size' => { '$gt' => 2 }}).each { |result| puts result }
col.update({'cost' => {'$gt' => 3}}, {'$inc' => {'cost' => -1}}, :multi => true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment