mongodb - duplicate key error index in mongoengine -


i have page model follow , page_id field isn't unique can't create instance page , error rises
operationerror: not save document (insertdocument :: caused ::11000 e11000 duplicate key error index: shopify.page.$pageid_1 dup key: { : null }) have no idea why duplicate key error rises when page_id field isn't unique

site model :

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')) 

it's because of old document in database in past have different fields , when new changes applied because of different objects type in collection when function running unable recognize type of object of field , go down !
1 solution dropping collection , if collection important can write script delete old objects , make new instance them.


Comments