Duplicate documents are expected to be inserted into the mongodb collection, so an index was created with unique=True
and dropDups=True
.
db.myCollection.create_index("timestamp", unique=True, dropDups=True)
However if the same set of documents are inserted twice, the first insert goes fine but the second insert throws the error
db.myCollection.insert(json.loads(df.to_json()).values())
DuplicateKeyError: E11000 duplicate key error index: myDb.myCollection.$timestamp_1 dup key: { : 1385290560000000000 }
I am confused as to why dropDups=True
is not working.