Re: [MongoMapper] Hashes, uneven behavior

23 views
Skip to first unread message

Jamie Orchard-Hays

unread,
May 23, 2013, 10:35:31 AM5/23/13
to mongo...@googlegroups.com
Mongodb's BSON does not have Symboles like Ruby or Clojure (called "Keywords"). So, Symbols are changed to Strings for storage in Mongo.

In other words, Ruby has the Symbol type, but BSON does not, so it uses the closest thing for storage, which is a String.

If you want to change them back to Symbols, then in your model class, you might have a from_mongo() method for that attribute.

Jamie

On May 22, 2013, at 5:43 PM, Heberto del Rio wrote:

Why is it that when in MongoMapper a key of type Hash is used the keys of that hash are saved as strings, even if symbols are used? How can this behavior be changed?

In the same way if a key has a type Array and hashes are used as the elements of this array the keys of the used hashes are saved as string, even if symbols are used?

To summarize, if hashes are used the keys are saved as strings, even if symbols are being used. Well not always the keys of a Documents are saved as strings but recovered as symbols. Mmmh very uneven behavior

Heberto del Rio

--
--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "MongoMapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongomapper...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages