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

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

    I still hit the 1000 limit with count so adapted dar's code (mine's a bit quick and dirty):

    class GetCount(webapp.RequestHandler):
        def get(self):
            query = modelname.all(keys_only=True)
    
            i = 0
            while True:
                result = query.fetch(1000)
                i = i + len(result)
                if len(result) < 1000:
                    break
                cursor = query.cursor()
                query.with_cursor(cursor)
    
            self.response.out.write('

    Count: '+str(i)+'

    ')

提交回复
热议问题