from pymongo import MongoClient import os import time client = MongoClient("mongodb://localhost:27017/") db = client.dropmatic keys = db.keys while True: with open("promo_codes.txt") as f: data = [{"key": i.strip()} for i in f.readlines()] os.remove("promo_codes.txt") with open("promo_codes.txt", "w") as d: pass if data: s = keys.insert_many(data) print(s.inserted_ids) else: print("Bekleniyor...") time.sleep(10)