Skip to content

Instantly share code, notes, and snippets.

@simonw
Created December 3, 2009 18:02
Show Gist options
  • Select an option

  • Save simonw/248372 to your computer and use it in GitHub Desktop.

Select an option

Save simonw/248372 to your computer and use it in GitHub Desktop.
def all_from_view(db, view_name, batch_size=100):
kwargs = {
'limit': batch_size,
'include_docs': True,
}
startkey_docid = None
last_served_id = None
while True:
if startkey_docid is not None:
kwargs['startkey_docid'] = startkey_docid
kwargs['startkey'] = True
print 'Kwargs: %s' % kwargs
vr = db.view(view_name, **kwargs)
if not vr.rows:
break
for row in vr.rows:
if row.id != last_served_id:
yield row
last_served_id = row.id
startkey_docid = vr.rows[-1]['id']
print 'startkey_docid now %s' % startkey_docid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment