I am trying to update a collection in mongodb that has around 100k documents through the code written below. However after running for around 50k documents it gives below error
pymongo.errors.CursorNotFound: Cursor not found, cursor id: 632871094123
mapping_id_tree_old=[]
mapping_id_tree_new=[]
for i in range(0,len(resulttree)):
resulttree1 = resulttree[i].values()[0:1]
mapping_id_tree_old.append(resulttree1[0][1])
mapping_id_tree_new.append(resulttree1[0][0])
dataNodeDictionary = dict(zip(mapping_id_old, mapping_id_new))
treeNodeDictionary = dict(zip(mapping_id_tree_old,mapping_id_tree_new))
it = treeNodeEmerald.find({"_id": {"$in": mapping_id_tree_new}})
for doc in it :
if(doc.get('dataNodeId')):
oldDataNodeObjectId = doc["dataNodeId"]
if(dataNodeDictionary.get(ObjectId(oldDataNodeObjectId))):
newDataNodeObjectId = dataNodeDictionary[ObjectId(oldDataNodeObjectId)]
oldDataNodeObjectIdstr = str(oldDataNodeObjectId)
newDataNodeObjectIdstr = str(newDataNodeObjectId)
treeNodeEmerald.update({"dataNodeId": oldDataNodeObjectIdstr}, {"$set": {"dataNodeId": newDataNodeObjectIdstr}})