开发者

Document updates using mongo-ruby-driver?

开发者 https://www.devze.com 2023-02-06 09:10 出处:网络
Assuming the following: irb> x irb> => {\"_id\"=> 123456, \"welcome\"=>\"Hi!\", \"welcome2\" => \"Enjoy your stay!\"}

Assuming the following:

irb> x
irb> => {"_id"=> 123456, "welcome"=>"Hi!", "welcome2" => "Enjoy your stay!"}
irb> coll.class
irb> => Mongo::Collection

How can I use the raw mongo-ruby-driver to update the document corresponding to x by using both the rewriting method and the atomic update method? (See http://api.mongodb.org/ruby/current/file.TUTORIAL.html#Updating_开发者_如何学Ca_Document)


given your example output, if you want to use the rewriting method it would be like this:

coll.update({"_id" => x["_id"]}, x)

or if you want to atomically change a value, it would be like this:

coll.update({"_id" => x["_id"]}, {"$set" => {"welcome" => "Hello There"}})
0

精彩评论

暂无评论...
验证码 换一张
取 消