After research, I found this link which shows you can update a field dynamically in mongoid:
Model#rename
Performs MongoDB's $rename modifier that renames a field atomically.
MONGOID
person.rename(:bday, :dob)
MONGODB COMMAND
collections["people"].update( { "_id" : ... }, { "$rename" : {
"bday" : "dob" } } )
According to this stackoverflow post, when the fourth paraemeter is set to true, it should update all your records. But it is not working. When I do the following:
Contact.rename('apple info', 'new_info', false, true)
And then query mongodb:
db.mongoid_container_contacts.find()
{ "_id" : ObjectId("558c50256d6163b255060000"), "apple info" : "etretrytr", ...
As you can see, 'apple info' remains in the existing records. Why isn't the name of the existing records being updated?