How to fetch more than 1000?

后端 未结 16 2006
囚心锁ツ
囚心锁ツ 2020-11-28 04:13

How can I fetch more than 1000 record from data store and put all in one single list to pass to django?

16条回答
  •  佛祖请我去吃肉
    2020-11-28 04:24

    This is close to the solution provided by Gabriel, but doesn't fetch the results it just counts them:

    count = 0
    q = YourEntityClass.all().filter('myval = ', 2)
    countBatch = q.count()
    while countBatch > 0:
        count += countBatch
        countBatch = q.with_cursor(q.cursor()).count()
    
    logging.info('Count=%d' % count)
    

    Works perfectly for my queries, and fast too (1.1 seconds to count 67,000 entities)

    Note that the query must not be an inequality filter or a set or the cursor will not work and you'll get this exception:

    AssertionError: No cursor available for a MultiQuery (queries using "IN" or "!=" operators)

提交回复
热议问题