-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
I have problem when I am trying to use update_all method on model with non existing field.
My User model is -
class User
include Mongoid::Document
field :name, type: String
end
NOTE: Here I have not included 'Mongoid::Attributes::Dynamic'
When I am trying update_all method on non existing field it is creating field on mongodb
2.1.3 :001 > User.all.to_a
=> #<User _id: 54e855837368773ff7000000, name: "Shweta">, #<User _id: 54e855877368773ff7010000, name: "Anuja">
2.1.3 :006 > User.where(name: 'Shweta').update_all(last_name: 'Kale')
=>
2.1.3 :007 > User.all.to_a
Documents from mongo shell
db.users.find();
{ "_id" : ObjectId("54e855877368773ff7010000"), "name" : "Anuja" } { "_id" : ObjectId("54e855837368773ff7000000"), "last_name" : "Kale", "name" : "Shweta" }It has created field last_name in mongodb
When I am trying to use update_attributes on user, its giving UnknownAttribute Error
2.1.3 :014 > User.last.update_attributes(last_name: 'Kale')
Mongoid::Errors::UnknownAttribute:
Is this bug or I am missing something?