mongoengine中的重复键错误索引

时间:2015-07-13 11:08:46

标签: mongodb mongoengine

我有Page模型如下,page_id字段不是unique,但我无法从Page创建实例,此错误会增加
        OperationError: Could not save document (insertDocument :: caused by ::11000 E11000 duplicate key error index: shopify.page.$pageId_1 dup key: { : null })page_id字段不是unique时,我不知道为什么重复键错误会上升

Site模型:

class Page(Document):

    # page identity
    page_id = StringField()
    store = ReferenceField('Store')
    is_product = BooleanField(default = False)
    is_homepage = BooleanField(default = False)
    product = ReferenceField('Product')
    requests = ListField(EmbeddedDocumentField('Request'))

    # page stat
    visitors = IntField(default = 0)
    views = IntField(default = 0)
    past_days = ListField(EmbeddedDocumentField('DayStat'))

1 个答案:

答案 0 :(得分:0)

是的,我还从field属性中删除了unique = True,然后删除了Collection并再次运行了代码。这样就解决了问题。