Add mongo transaction
This commit is contained in:
parent
c03ebbf853
commit
d0e9d6913d
@ -28,11 +28,15 @@ def main():
|
||||
if obj_type not in collections:
|
||||
collections[obj_type] = []
|
||||
collections[obj_type].append(obj)
|
||||
print("Inserting all data")
|
||||
mongo[DB][COLLECTION].insert_many(items)
|
||||
for collection in collections:
|
||||
print(f"Inserting collection: {collection}")
|
||||
mongo[DB][collection].insert_many(collections[collection])
|
||||
# print("Inserting all data")
|
||||
# mongo[DB][COLLECTION].insert_many(items)
|
||||
with mongo.start_session() as s:
|
||||
s.start_transaction()
|
||||
s[DB].drop_database()
|
||||
for collection in collections:
|
||||
print(f"Inserting collection: {collection}")
|
||||
mongo[DB][collection].insert_many(collections[collection])
|
||||
s.commit_transaction()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user