Reputation: 11903
I have the following MongoDB update operation, but it doesnt seem to work, anyone know why?
User.collection.update({ _id: BSON::ObjectId("5018ed448712ff240e0000a0") },
{ "$set" => { name: "ben" } })
It does not throw an error, but just some integer which I am guessing is the doc size.
I am using Mongoid 2.4.10/Rails 3.2.7
Upvotes: 3
Views: 1275
Reputation: 14171
If you are using Mongoid, you coule just do a find and update:
User.find("5018ed448712ff240e0000a0").update_attributes!(name: "ben")
or you could use set:
User.find("5018ed448712ff240e0000a0").set(:name, "ben")
Note that set()
takes 2 arguments; it does not accept a hash as an argument
Upvotes: 2
Reputation: 10630
Can you use mongoid API instead and use following command:
User.find("5018ed448712ff240e0000a0").set(name: "ben")
Upvotes: 0