I have a dataset that I am pulling from an API. The dataset contains fields such as store_id, store_description, monthly_sales, total_sales.
There are 16,219 records in this dataset
I would like to automate the pulling of this data but when I pull from the API more than once I get duplicate records of the data instead of each record being updated. Below is the code I am using to update the data:
for i in json.loads(data):
for j in col.find({}):
if i['store_id'] == j['store_id']:
col.update_one({j}, {i})
else:
col.insert_one({i})
I am not really sure what exaclty I am doing wrong here. I would appreciate any help.
question from:
https://stackoverflow.com/questions/65876192/pymongo-and-updating-records 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…