Skip to content

Instantly share code, notes, and snippets.

@dsaiztc
Last active July 31, 2018 07:42
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 dsaiztc/a0860f5bf244ef048b4e61b1a0c9e2b6 to your computer and use it in GitHub Desktop.
Save dsaiztc/a0860f5bf244ef048b4e61b1a0c9e2b6 to your computer and use it in GitHub Desktop.
cursor = None
rows = []
total_rows = -1
while(True):
try:
total_rows += 1
row = next(cursor)
rows.append(row)
except bson.errors.InvalidBSON:
logger.exception('Failed to parse document')
except StopIteration:
break
logger.debug('Parsed {}/{} documents from Mongo DB collection (out of a total count of {})'.format(
cursor.retrieved,
total_rows,
cursor.count()
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment