Hi

You will need to use a cursor combined with a keys_only query (for
efficiency) and keep
resubmitting the cursor until you get all the results.

If you plan to do this in appengine process rather than via the
remote_api you will probably need to use a chain of tasks
to achieve the result if you have a lot of entities.

In python it looks  something like the following (I don't do any work
with java on app engine)

def count(query):
   i = 0
   while True:
      result = query.fetch(1000)
      i = i + len(result)
      if len(result) < 1000:
          break
      cursor = query.cursor()
      query.with_cursor(cursor)
   return i

myquery = mymodels.MyModel.all(keys_only=True)

x = count(myquery)

Hope this helps

Rgds

T


On Apr 9, 7:36 am, Patrick Twohig <[email protected]> wrote:
> I'm trying to figure out a way to count entities matching a certain
> criteria.  I was thinking of doing a key-only query and using
> PreparedQuery.countEntities() (Java).  However, when I do that, it always
> returns a value no higher than 1000.  Is there a way to get an accurate
> count of all entities matching a query without having to do something
> like....
>
> int count = datastore.prepare( query.setKeysOnly()
> ).asList(FetchOptions.Builder.limit(Integer.MAX_VALUE)).size() ?
>
> Thanks,
> Patrick.
>
> --
> Patrick H. Twohig.
>
> Namazu Studios
> P.O. Box 34161
> San Diego, CA 92163-4161
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/google-appengine?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to