I prefilter 3 collections and build a single new collection from it. To do this i iterate over the cursor objects like this (monate, wochen, tage are justs lists containing relevant datetime objects:
monate_final = collection1.find({"NewDate": {"$in": list(monate)}})
wochen_final = collection2.find({"NewDate": {"$in": list(wochen)}})
tage_final = collection3.find({"NewDate": {"$in": list(tage)}})
master_list = [monate_final, wochen_final, tage_final]
for collection in master_list:
for document in collection:
self.target.insert_one(document)
The code works, but since the the final collections contains > 100 millions records, the process just takes forever. I did not find a more efficient way to do this. Building a pandas DataFrame and then use insert_many() does not work due to memory limitation. Can anyone help me?