When attributes() is called on a Mongoid model object it excludes the fields with nil values, is there a way to get all the fields irrespective of their values?
media = Media.first
media.attributes #=> ignores nil values
Also, FYI this happens when a record is created with only a few attributes, but when we create a record by assigning nil values to the remaining fields explicitly it works fine!
Any help would be highly appreciated!
mongoidused to remove empty fields. If you kept some fields empty on insert,mongoidwill removes them.Use
media.to_jsoninstead for your case.