-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
According to the documentation for Mongoid 3:
Even though MongoDB is a schemaless database, most uses will be with web applications where form parameters always come to the server as strings. Mongoid provides an easy mechanism for transforming these strings into their appropriate types through the definition of fields in a Mongoid::Document.
If I create a document with the following definition:
require 'mongoid' class Doc include Mongoid::Document field :val, type: Array end
... and then do this:
d = Doc.new d.val = "1,2,3" d.save!
... I end up with this:
#<Doc _id: 52fa6d5ac6992f8bc8000003, val: "1,2,3">
Why is the value not being transformed to an Array before the document is saved? This seems to go against the very reason for defining field types in the first place.
Am I missing some option I need to toggle or additional validation DSL I need to include in order to get this working? At the very least, I would expect an error to be thrown when I try to set a field to a value of a different type and then attempt to save.
Thanks for any help, in advance.