How does one get a count of rows in a Datastore model in Google App Engine?

后端 未结 8 1886
日久生厌
日久生厌 2020-12-05 10:13

I need to get a count of records for a particular model on App Engine. How does one do it?

I bulk uploaded more than 4000 records but modelname.count() only shows me

8条回答
  •  甜味超标
    2020-12-05 10:37

    As of release 1.3.6, there is no longer a cap of 1,000 on count queries. Thus you can do the following to get a count beyond 1,000:

    count = modelname.all(keys_only=True).count()
    

    This will count all of your entities, which could be rather slow if you have a large number of entities. As a result, you should consider calling count() with some limit specified:

    count = modelname.all(keys_only=True).count(some_upper_bound_suitable_for_you)
    

提交回复
热议问题