Retrive all the entities from a datastore

750 Views Asked by At

I m using the low-level API in the App Engine Datastore . To retrieve an entity I use

Entity post = datastore.get(postKey);

but this code will return only the post with this postkey. What shall i do if i want to return all the posts ?

1

There are 1 best solutions below

1
fmt.Println.MKO On BEST ANSWER

you need todo a query, not a get,

get ist just a single instance by id, query is result of your query.

just do:

// Use class Query to assemble a query
Query q = new Query("Post");

// Use PreparedQuery interface to retrieve results
PreparedQuery pq = datastore.prepare(q);


for (Entity result : pq.asIterable()) {
  String postName = (String) result.getProperty("PostName");
}