Created
February 4, 2021 12:33
-
-
Save gidgid/fabb8ff098d943a3f7df4c490b63c128 to your computer and use it in GitHub Desktop.
using more_itertools chunked to save batches
This file contains hidden or 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
from typing import List | |
from more_itertools import chunked | |
def batch_insert(col, items: List[dict], batch_size: int): | |
batches = chunked(items, batch_size) # 1 | |
for batch in batches: | |
col.insert_many(batch) # 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment