mongoid/mongoid-site — Issue #122: Add Custom Index Names
Author: durran
Created: 2012-03-08 09:08:42+00:00
State: open

From: https://github.com/mongoid/mongoid/issues/1796

Make note that Mongoid allows you to specify a custom name for an index -- http://mongoid.org/docs/indexing.html

I ran into an error where the auto-generated index name on my compound index was too long. I couldn't find any reference to how you would override that name using Mongoid, but I knew it was possible with Mongo directly. I took a guess and appended ```:name => 'my name'```, and it worked. I just think it might be helpful to have this noted in the docs.

```
b rake db:mongoid:create_indexes
Failed to create indexes for Consumer:
Mongo::OperationFailure:Failed to create index {:name=>"something_very_long", :ns=>"project_development.consumers", :key=>{"all" => 1, "my" => 1, "keys" => 1}, :unique=>false}
with the following error: 10080: ns name too long, max size is 128
```