Here is the senario. I have a model called Permission. Lets assume it looks like this:
class Permission(Document):
meta = {'collection': 'permission'}
permission = DictField()
owner = ReferenceField('user')
This inherits from the mongoengine's Document class. Thus when I save an instance of this, a collection is automatically created named permission in the database.
I want to be able to change the collection name dynamically. For example if I had a Contacts model and wanted to save the permission for the Contact model I dont want it to go into the permission collection but be saved in a separate collection called contact_permission.
I have used the feature/dynamic_collection_naming branch for mongoengine. I am not able to figure out how to get this working. I have tried this:
p = Permission()
...
p.meta['collection'] = 'contact_permission'
p.save()
But this does not work. Could you help me out please.