mongoengine: Error when using unique_with and inheritance

When upgrading to mongo 2.6 I get this error (which I don’t get under mongo 2.4).

Trying to save an instance of my document (SubclassDoc):

  File "/Users/amos/Work/rfb-dev/eggs/mongoengine-0.8.7-py2.7.egg/mongoengine/document.py", line 294, in save
    raise OperationError(message % unicode(err))
OperationError: Could not save document (command SON([('createIndexes', u'feed'), ('indexes', [{'name': u'content_1_user_1', 'key': SON([('content', 1), ('user', 1)]), 'unique': True, 'background': False, 'sparse': True, 'dropDups': False}])]) failed: Index with name: content_1_user_1 already exists with different options)

I think the problem is that I have a base document class and a class that derives it that want to create different unique indexes on the same collection.

class FeedItem(Document):
    user = ReferenceField('User', required=True)
    content = ReferenceField('Content', required=True, unique_with='user')

class SubclassDoc(BaseDoc):
    pass
>>> BaseDoc._unique_with_indexes()
[{'fields': [('content', 1), ('user', 1)], 'unique': True, 'sparse': False}]
>>> SubclassDoc._unique_with_indexes()
[{'fields': [('content', 1), ('user', 1)], 'unique': True, 'sparse': True}]

I don’t understand why this works on mongo 2.4 but not on mongo 2.6.

Thanks for any suggestions!

About this issue

  • Original URL
  • State: open
  • Created 10 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

For future ref, this bug still exist with mongo >=3.2 and latest mongoengine (0.17)