Because of MongoDB’s ability to store rich documents, MongoMapper supports most of Ruby’s data types out of the box, such as Array, Float, Hash, Integer, NilClass, Object, String, and Time. In addition to those, MongoMapper adds support for Binary, Boolean, Date, ObjectId, and Set by serializing to and from Mongo safe types.
The great thing about MongoMapper is that you can create your own types to make your models more pimp. All that is required to make your own type is to define the class and add the to_mongo and from_mongo class methods. For example, here is a type that always downcases strings when saving to the database:
Or, if you are curious about a slightly more complex example, here is a type that is used in MongoMapper’s tests:
This example actually serializes to an array for storage in Mongo, but returns an actual WindowSize object after retrieving from the database.