Skip to content

Instantly share code, notes, and snippets.

@gidgid
Created February 4, 2021 12:33
Show Gist options
  • Save gidgid/fabb8ff098d943a3f7df4c490b63c128 to your computer and use it in GitHub Desktop.
Save gidgid/fabb8ff098d943a3f7df4c490b63c128 to your computer and use it in GitHub Desktop.
using more_itertools chunked to save batches
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