Skip to content

Instantly share code, notes, and snippets.

@sbnajardhane
Created August 2, 2020 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbnajardhane/755cc0ffa6d8332400da411def2dd81c to your computer and use it in GitHub Desktop.
Save sbnajardhane/755cc0ffa6d8332400da411def2dd81c to your computer and use it in GitHub Desktop.
Code snippet to show performance difference between bulk vs individual insert operation
users_info = read_users_info_from_csv(file_path)
for user in users_info:
LoyaltyUser(**user).save()
## With bulk operations:
users_info = read_users_info_from_csv(file_path)
users_to_insert = list()
for user in users_info:
users_to_insert.append(InsertOne(user))
db.LoyaltyUser.bulk_write(users_to_insert)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment