Skip to content

Instantly share code, notes, and snippets.

@shingara
Created March 24, 2011 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shingara/885015 to your computer and use it in GitHub Desktop.
Save shingara/885015 to your computer and use it in GitHub Desktop.
require 'mongo'
col = Mongo::Connection.new.db("bug-update-set").collection('test')
col.insert({
:name => 'hello',
:data_stats => [
{:name => 'first', :_type => 'big'},
{:name => 'second', :_type => 'medium'},
{:name => 'third', :_type => 'big'},
{:name => 'four', :_type => 'big'},
]
})
col.insert({
:name => 'hello',
:data_stats => [
{:name => 'first', :_type => 'big'},
{:name => 'second', :_type => 'medium'},
{:name => 'third', :_type => 'big'},
{:name => 'four', :_type => 'big'},
]
})
col.find({"data_stats._type" => 'big'}).each { |doc| puts doc.inspect }
col.update({"data_stats._type" => 'big'}, {"$set" => {"data_stats.$._type" => 'small'}}, {:multi => true})
p 'after update'
p col.find({"data_stats._type" => 'big'}).count()
col.find({"data_stats._type" => 'big'}).each { |doc| puts doc.inspect }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment