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

后端 未结 8 1876
日久生厌
日久生厌 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:43

    Another solution is using a key only query and get the size of the iterator. The computing time with this solution will rise linearly with the amount of entrys:

    Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
    KeyFactorykeyFactory = datastore.newKeyFactory().setKind("MyKind");
    Query query = Query.newKeyQueryBuilder().setKind("MyKind").build();
    int count = Iterators.size(datastore.run(query));
    

提交回复
热议问题