Kind query

Kind query.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

C#

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries . For more information, see the Datastore mode C# API reference documentation .

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  Query 
  
 query 
  
 = 
  
 new 
  
 Query 
 ( 
 "__kind__" 
 ); 
 var 
  
 kinds 
  
 = 
  
 new 
  
 List<string> 
 (); 
 foreach 
  
 ( 
 Entity 
  
 entity 
  
 in 
  
 _db 
 . 
 RunQuery 
 ( 
 query 
 ). 
 Entities 
 ) 
 { 
  
 kinds 
 . 
 Add 
 ( 
 entity 
 . 
 Key 
 . 
 Path 
 [ 
 0 
 ]. 
 Name 
 ); 
 }; 
 

Go

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries . For more information, see the Datastore mode Go API reference documentation .

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  query 
  
 := 
  
 datastore 
 . 
 NewQuery 
 ( 
 "__kind__" 
 ). 
 KeysOnly 
 () 
 keys 
 , 
  
 err 
  
 := 
  
 client 
 . 
 GetAll 
 ( 
 ctx 
 , 
  
 query 
 , 
  
 nil 
 ) 
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 log 
 . 
 Fatalf 
 ( 
 "client.GetAll: %v" 
 , 
  
 err 
 ) 
 } 
 kinds 
  
 := 
  
 make 
 ([] 
 string 
 , 
  
 0 
 , 
  
 len 
 ( 
 keys 
 )) 
 for 
  
 _ 
 , 
  
 k 
  
 := 
  
 range 
  
 keys 
  
 { 
  
 kinds 
  
 = 
  
 append 
 ( 
 kinds 
 , 
  
 k 
 . 
 Name 
 ) 
 } 
 

Java

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries . For more information, see the Datastore mode Java API reference documentation .

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  Query<Key> 
  
 query 
  
 = 
  
 Query 
 . 
 newKeyQueryBuilder 
 (). 
 setKind 
 ( 
 "__kind__" 
 ). 
 build 
 (); 
 List<String> 
  
 kinds 
  
 = 
  
 new 
  
 ArrayList 
<> (); 
 QueryResults<Key> 
  
 results 
  
 = 
  
 datastore 
 . 
 run 
 ( 
 query 
 ); 
 while 
  
 ( 
 results 
 . 
 hasNext 
 ()) 
  
 { 
  
 kinds 
 . 
 add 
 ( 
 results 
 . 
 next 
 (). 
 getName 
 ()); 
 } 
 

Node.js

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries . For more information, see the Datastore mode Node.js API reference documentation .

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  async 
  
 function 
  
 runKindQuery 
 () 
  
 { 
  
 const 
  
 query 
  
 = 
  
 datastore 
 . 
 createQuery 
 ( 
 '__kind__' 
 ). 
 select 
 ( 
 '__key__' 
 ); 
  
 const 
  
 [ 
 entities 
 ] 
  
 = 
  
 await 
  
 datastore 
 . 
 runQuery 
 ( 
 query 
 ); 
  
 const 
  
 kinds 
  
 = 
  
 entities 
 . 
 map 
 ( 
 entity 
  
 = 
>  
 entity 
 [ 
 datastore 
 . 
 KEY 
 ]. 
 name 
 ); 
  
 console 
 . 
 log 
 ( 
 'Kinds:' 
 ); 
  
 kinds 
 . 
 forEach 
 ( 
 kind 
  
 = 
>  
 console 
 . 
 log 
 ( 
 kind 
 )); 
  
 return 
  
 kinds 
 ; 
 } 
 

PHP

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries . For more information, see the Datastore mode PHP API reference documentation .

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  $query = $datastore->query() 
 ->kind('__kind__') 
 ->projection(['__key__']); 
 $result = $datastore->runQuery($query); 
 /* @var array<string> $kinds */ 
 $kinds = []; 
 foreach ($result as $kind) { 
 $kinds[] = $kind->key()->pathEnd()['name']; 
 } 
 

Python

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries . For more information, see the Datastore mode Python API reference documentation .

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  from 
  
 google.cloud 
  
 import 
  datastore 
 
 # For help authenticating your client, visit 
 # https://cloud.google.com/docs/authentication/getting-started 
 client 
 = 
  datastore 
 
 . 
  Client 
 
 () 
 query 
 = 
 client 
 . 
  query 
 
 ( 
 kind 
 = 
 "__kind__" 
 ) 
 query 
 . 
  keys_only 
 
 () 
 kinds 
 = 
 [ 
 entity 
 . 
 key 
 . 
  id_or_name 
 
 for 
 entity 
 in 
 query 
 . 
 fetch 
 ()] 
 

Ruby

To learn how to install and use the client library for Datastore mode, see Datastore mode client libraries . For more information, see the Datastore mode Ruby API reference documentation .

To authenticate to Datastore mode, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  query 
  
 = 
  
 datastore 
 . 
 query 
 ( 
 "__kind__" 
 ) 
  
 . 
 select 
 ( 
 "__key__" 
 ) 
 kinds 
  
 = 
  
 datastore 
 . 
 run 
 ( 
 query 
 ) 
 . 
 map 
  
 do 
  
 | 
 entity 
 | 
  
 entity 
 . 
 key 
 . 
 name 
 end 
 

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser .

Design a Mobile Site
View Site in Mobile | Classic
Share by: