How to fetch more than 1000?

后端 未结 16 1977
囚心锁ツ
囚心锁ツ 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:21

    entities = []
    for entity in Entity.all():
        entities.append(entity)
    

    Simple as that. Note that there is an RPC made for every entity which is much slower than fetching in chunks. So if you're concerned about performance, do the following:

    If you have less than 1M items:

    entities = Entity.all().fetch(999999)
    

    Otherwise, use a cursor.

    It should also be noted that:

    Entity.all().fetch(Entity.all().count())
    

    returns 1000 max and should not be used.

提交回复
热议问题