Created
August 2, 2020 08:32
-
-
Save sbnajardhane/755cc0ffa6d8332400da411def2dd81c to your computer and use it in GitHub Desktop.
Code snippet to show performance difference between bulk vs individual insert operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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