ScottyB
ScottyB

Reputation: 45

GAE Datastore querying by index

I have created entities in the datastore. I want to use the index assigned to them by the datstore for queries. i.e get an iterable back where the id is greater than a given number e.g.

Query q = new Query("MyEntity");
q.addFilter("id",Query.FilterOperator.GREATER_THAN_OR_EQUAL, startId);
PreparedQuery pq = datastore.prepare(q);

I know I can get back an individual entity back via id - but how to get a list ?

Cheers,

Upvotes: 1

Views: 183

Answers (2)

Dave W. Smith
Dave W. Smith

Reputation: 24966

If your intent is to remember where you left off and continue there on a subsequent query, consider using a query cursor. The example on that page might give you some further options.

Upvotes: 0

Riley Lark
Riley Lark

Reputation: 20890

Iterable<Entity> myEntities = pq.asIterable();
List<Entity> myEntitiesInAList = pq.asList(FetchOptions.Builder.withChunkSize(500));

Side note: "id" is not the name of the key assigned automatically by App Engine. I think you must use __key__ as the property name to do queries on it, and construct a full key as the search parameter, not just the long id.

Upvotes: 1

Related Questions