pymonodb 批量更新数据
from pymongo import UpdateOne action = list() with open("/Users/wyc/work/geneSearch/server/search/userdatagene.fixed.txt", "r") as f: count = 0for item in f: c = item.replace('"', "").replace("\n", "") a = c.split(" ") actions = UpdateOne({"Sample_ID": a[0]}, {"$set": {"var_gene": a[1]}}, upsert=False) action.append(actions) if len(action) == 10000: db.userdatagene.bulk_write(action) count += 10000 print("批量插入数量: {}".format(count)) action.clear() if len(action) > 0: db.userdatagene.bulk_write(action) count += len(action) print("批量插入数量2: {}".format(count)) action.clear()