MongoEngine/mongoengine — pull request #675 by claymation (2014-06-25 15:09:27+00:00)
Title: Allow index specs to be composed from raw strings

I'd like to be able to use MongoEngine to create an index on arbitrary keys of a `DictField`, *e.g.*:

class MyDoc(Document):
provider_ids = DictField()
meta = {
"indexes": ["provider_ids.foo", "provider_ids.bar"],
}

The use case is that I'm ingesting data from various providers and want to be able to track the id that each provider has assigned to the data in a `DictField`. I *could* track the ids in separate top-level fields (`foo_id`, `bar_id`), but grouping them under a single `DictField` feels cleaner to me and makes it easier to `.exclude()` the ids when I don't need them.

Before this patch, attempting to specify an index with arbitrary keys fails with `AttributeError: 'str' object has no attribute 'db_field'`. If this patch looks like the right approach, I'll write up a test case and resubmit.