class MongoABC:
def __init__(self):
# all the variable initialisation
...
def insert_to_mongo(self, user_id, json):
self.db.collection.insert_one(json)
If I create an instance of MongoABC
and call the insert_to_mongo
function more than once, it generates a E11000 duplicate key error on the _id
.
It performs it in real time so previous solutions of making a copy of inserting document(json
), upserting it or deleting the _id
as suggested here doesn't seem to work in this case.
The _id
always remain constant as long as the MongoABC
instance is same. So how do we create an unique _id
for every time we call insert_one()
?
This error is specific to mongo servers running in Microsoft azure.