Syncing MongoDB Data

Hey, I am a new User of MongoDB. I am working with Large amount of Transaction data which is updated periodically after each day or week. I created my code for this use where i am using pymongo.UpdateOne but as i have large amount of data, I want to use UpdateMany. Here’s the snippet of my code:

client = MongoClient()
database = client['Eg']
collection = database['eg']
start =

df = pd.read_csv("eg.csv")
df['_id'] = df["Factory_Id"] + df["Order ID"]
data = df.to_dict(orient="records")

requests = []
for doc in data:
    filter = {'_id': doc['_id']}
    update = {'$set': doc}
    request = pymongo.UpdateOne(filter, update, upsert=True)

if requests:
    result = collection.bulk_write(requests)

Here I am using UpdateOne for syncing but i want it sync by once and not use for-loop with the help of “UpdateMany”.

As far as I can tell you are already using the API correctly. UpdateMany is only useful for applying a single update across multiple matching documents, for example adding a new field to all documents in the collection:

coll.update_many({}, {"$set": {"new": 0}})

Since your updates are scoped to a single _id UpdateOne (or ReplaceOne) is appropriate.