jnunemaker/mongomapper — pull request #351 by spinosa (2011-11-22 21:43:06+00:00)
Title: Key aliasing

...because Mongo stores the entire key with each document, and that's terrible with large datasets.

This patch allows you to add the :alias option to any key which will define what string is actually stored in Mongo as the key. This is done transparently, so your code can continue to use the human-readable long key while persisting in mongo with the (presumably shorter) alias.

For example:

```ruby
class User
include MongoMapper::Document
key :email_address, String, :alias => :e
end

u = User.find_by_email_address("spinosa@gmail.com")
u.email_address = "dan@shelby.tv"
u.save

#user in db looks like {_id: 'NormalObjectId', e: 'dan@shelby.tv' }
```

I fully expect, understand and would appreciate feedback on this pull request; I look forward to improving this topic branch.

Thanks for taking the time to look it over.