[英]mongo-ruby-driver will not create a new document on upsert when there is a custom _id
[英]Document updates using mongo-ruby-driver?
假設如下:
irb> x
irb> => {"_id"=> 123456, "welcome"=>"Hi!", "welcome2" => "Enjoy your stay!"}
irb> coll.class
irb> => Mongo::Collection
如何使用原始mongo-ruby-driver通過使用重寫方法和原子更新方法更新與x對應的文檔? (見http://api.mongodb.org/ruby/current/file.TUTORIAL.html#Updating_a_Document )
給出你的示例輸出,如果你想使用重寫方法,它將是這樣的:
coll.update({"_id" => x["_id"]}, x)
或者如果你想原子地改變一個值,它將是這樣的:
coll.update({"_id" => x["_id"]}, {"$set" => {"welcome" => "Hello There"}})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.