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 = datetime.now()
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)
requests.append(request)
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”.