Go 1.11 has reached end of support
and will be
deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Go 1.11
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Go
1.11 applications will continue to run and receive traffic after their
deprecation date. We
recommend that you
migrate to the latest supported version of Go.
Retrieving query results
Stay organized with collections
Save and categorize content based on your preferences.
After constructing a query, you can specify a number of retrieval options to
further control the results it returns.
See datastore queries for more information on structuring queries for your app.
Iterating through query results
When iterating through the results of a query using the Run
method of a Query
value, Cloud Datastore retrieves the results in batches. By default each batch contains 20 results. You can continue iterating through query results until all are returned or the request times out.
To iterate over each entity that matches your query, use the
Run
method to obtain an
Iterator
, with which you can step through each entity using the
Iterator
's
Next
method.
To retrieve all entities matching your query at once, use the GetAll
method.
Retrieving selected properties from an entity
To retrieve only selected properties of an entity rather than the entire entity, use a projection query. This type of query runs faster and costs less than one that returns complete entities.
Similarly, a keys-only query saves time and resources by returning just the keys to the entities it matches, rather than the full entities themselves. To create this type of query, call the KeysOnly
method when constructing the Query
.:
Setting a limit for your query
You can specify a limit for your query to control the maximum number of results returned in one batch. The following example retrieves the five tallest people from Cloud Datastore:
What's next?
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-25 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[[["\u003cp\u003eThis API is designed for first-generation runtimes, with a migration guide available for upgrading to App Engine Go 1.12+ second-generation runtimes.\u003c/p\u003e\n"],["\u003cp\u003eQuery results can be iterated through using the \u003ccode\u003eRun\u003c/code\u003e method, which retrieves results in batches, or retrieved all at once with the \u003ccode\u003eGetAll\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eProjection queries allow for the retrieval of selected properties from an entity, which is faster and more cost-effective than retrieving full entities.\u003c/p\u003e\n"],["\u003cp\u003eKeys-only queries, created by calling the \u003ccode\u003eKeysOnly\u003c/code\u003e method, save resources by only returning the keys of matching entities.\u003c/p\u003e\n"],["\u003cp\u003eYou can limit the number of results returned by a query in a single batch by specifying a limit using the \u003ccode\u003eLimit\u003c/code\u003e method.\u003c/p\u003e\n"]]],[],null,[]]