If empty, returns entities of all kinds. Must be set in order to filter
results. While you may supply as many kinds as you wish, datastore currently
only accepts one at a time.
Example:
$query->kind('Person');
Parameter
Name
Description
kinds
array|string
The kind or kinds to return. Only a single kind
is currently supported.
Either a string property name or
an array representation of Property/Composite filter returned
by Filter::and(), Filter::or() and Filter::where().
operator
string|null
[optional] The operator to use in the filter
if property name is used in the first argument. A list of
allowed operators may be foundhere.
Short comparison operators are provided for convenience and are
mapped to their datastore-compatible equivalents. Available short
operators are=,!=,<,<=,>,>=,INandNOT IN.
value
mixed
[optional] The value to check if property name is
used in the first argument.
[optional] The direction to order in. Google
Cloud PHP provides class constants which map to allowed Datastore
values. Those constants areQuery::ORDER_DESCENDINGandQuery::ORDER_ASCENDING.Defaults toQuery::ORDER_ACENDING.
[[["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-09-04 UTC."],[],[],null,["# Cloud Datastore Client - Class Query (1.33.1)\n\nVersion latestkeyboard_arrow_down\n\n- [1.33.1 (latest)](/php/docs/reference/cloud-datastore/latest/Query.Query)\n- [1.33.0](/php/docs/reference/cloud-datastore/1.33.0/Query.Query)\n- [1.32.3](/php/docs/reference/cloud-datastore/1.32.3/Query.Query)\n- [1.31.0](/php/docs/reference/cloud-datastore/1.31.0/Query.Query)\n- [1.30.0](/php/docs/reference/cloud-datastore/1.30.0/Query.Query)\n- [1.29.2](/php/docs/reference/cloud-datastore/1.29.2/Query.Query)\n- [1.28.2](/php/docs/reference/cloud-datastore/1.28.2/Query.Query)\n- [1.26.0](/php/docs/reference/cloud-datastore/1.26.0/Query.Query)\n- [1.25.0](/php/docs/reference/cloud-datastore/1.25.0/Query.Query)\n- [1.24.4](/php/docs/reference/cloud-datastore/1.24.4/Query.Query)\n- [1.23.0](/php/docs/reference/cloud-datastore/1.23.0/Query.Query)\n- [1.22.1](/php/docs/reference/cloud-datastore/1.22.1/Query.Query)\n- [1.21.2](/php/docs/reference/cloud-datastore/1.21.2/Query.Query)\n- [1.19.0](/php/docs/reference/cloud-datastore/1.19.0/Query.Query)\n- [1.18.1](/php/docs/reference/cloud-datastore/1.18.1/Query.Query)\n- [1.17.1](/php/docs/reference/cloud-datastore/1.17.1/Query.Query) \nReference documentation and code samples for the Cloud Datastore Client class Query.\n\nRepresents a Cloud [Datastore Query](https://cloud.google.com/datastore/docs/concepts/queries)\n\nQueries can be created either by using the builder pattern, or by providing\na [Query](https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#query)\nwhen creating this object.\n\nExample: \n\n use Google\\Cloud\\Datastore\\DatastoreClient;\n\n $datastore = new DatastoreClient();\n\n $query = $datastore-\u003equery();\n $query-\u003ekind('Companies');\n $query-\u003efilter('companyName', '=', 'Google');\n\n $res = $datastore-\u003erunQuery($query);\n foreach ($res as $company) {\n echo $company['companyName']; // Google\n }\n\n // Queries can also be constructed using a\n // [Query Object](https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#query):\n $query = $datastore-\u003equery([\n 'query' =\u003e [\n 'kind' =\u003e [\n [\n 'name' =\u003e 'Companies'\n ]\n ],\n 'filter' =\u003e [\n 'propertyFilter' =\u003e [\n 'op' =\u003e 'EQUAL',\n 'property' =\u003e [\n 'name' =\u003e 'companyName'\n ],\n 'value' =\u003e [\n 'stringValue' =\u003e 'Google'\n ]\n ]\n ]\n ]\n ]);\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ Datastore \\\\ Query\n\nMethods\n-------\n\n### __construct\n\n### projection\n\nSet the Query Projection.\n\nAccepts an array of properties. If set, only these properties will be\nreturned.\n\nExample: \n\n $query-\u003eprojection(['firstName', 'lastName']);\n\n### keysOnly\n\nSet the query to return only keys (no properties).\n\nExample: \n\n $query-\u003ekeysOnly();\n\n### kind\n\nSet the Kind to query.\n\nIf empty, returns entities of all kinds. Must be set in order to filter\nresults. While you may supply as many kinds as you wish, datastore currently\nonly accepts one at a time.\n\nExample: \n\n $query-\u003ekind('Person');\n\n### filter\n\nSee also:\n\n- [Allowed Operators](https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#operator_1)\n\n### hasAncestor\n\nQuery for entities by their ancestors.\n\nKeys can be provided either via a [Google\\\\Cloud\\\\Datastore\\\\Key](/php/docs/reference/cloud-datastore/latest/Key)\nobject, or by providing a kind, identifier and (optionally) an identifier\ntype.\n\nExample: \n\n $key = $datastore-\u003ekey('Person', 'Bob');\n $query-\u003ehasAncestor($key);\n\n // Specifying an identifier type\n $key = $datastore-\u003ekey('Robots', '1337', [\n 'identifierType' =\u003e Key::TYPE_NAME\n ]);\n $query-\u003ehasAncestor($key);\n\n### order\n\nSee also:\n\n- [Allowed Directions](https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#Direction)\n\n### distinctOn\n\nThe properties to make distinct.\n\nThe query results will contain the first result for each distinct\ncombination of values for the given properties (if empty, all results\nare returned).\n\nExample: \n\n $query-\u003edistinctOn('lastName');\n\n### start\n\nSee also:\n\n- [Cursors, Limits and Offsets](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets)\n\n### end\n\nSee also:\n\n- [Cursors, Limits and Offsets](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets)\n\n### offset\n\nSee also:\n\n- [Cursors, Limits and Offsets](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets)\n\n### limit\n\nSee also:\n\n- [Cursors, Limits and Offsets](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets)\n\n### canPaginate\n\nIndicate that this type does support automatic pagination.\n\n### queryObject\n\nReturn a service-compliant array.\n\n### queryKey\n\nReturn the query_type union field name.\n\n### aggregation\n\n### jsonSerialize\n\nConstants\n---------\n\n### OP_DEFAULT\n\n Value: self::OP_EQUALS\n\n### OP_LESS_THAN\n\n Value: 'LESS_THAN'\n\n### OP_LESS_THAN_OR_EQUAL\n\n Value: 'LESS_THAN_OR_EQUAL'\n\n### OP_GREATER_THAN\n\n Value: 'GREATER_THAN'\n\n### OP_GREATER_THAN_OR_EQUAL\n\n Value: 'GREATER_THAN_OR_EQUAL'\n\n### OP_EQUALS\n\n Value: 'EQUAL'\n\n### OP_NOT_EQUALS\n\n Value: 'NOT_EQUAL'\n\n### OP_IN\n\n Value: 'IN'\n\n### OP_NOT_IN\n\n Value: 'NOT_IN'\n\n### OP_HAS_ANCESTOR\n\n Value: 'HAS_ANCESTOR'\n\n### ORDER_DEFAULT\n\n Value: self::ORDER_ASCENDING\n\n### ORDER_DESCENDING\n\n Value: 'DESCENDING'\n\n### ORDER_ASCENDING\n\n Value: 'ASCENDING'"]]