ebt_dev ebt_dev - 3 months ago 35
Java Question

How to put/get multiple entities at once in Google cloud Datastore using java

In the documentation, I didn't find how I can put or retrieve multiple entities at once. further, by using GQL, I was not able to execute queries such select * from k where __ key __ in ('key1','key2','key3').

Can any one help me please, how I can insert/ retrieve multiple entities at once using java??

Thanks,

Answer

In Cloud Datastore, a LookupRequest and CommitRequest allow multiple keys and entities, respectively, to be specified. For example:

LookupRequest request = LookupRequest.newBuilder()
    .addKey(key1)
    .addKey(key2)
    .build();

or:

CommitRequest request = CommitRequest.newBuilder()
    .setMode(CommitRequest.Mode.NON_TRANSACTIONAL)
    .setMutation(Mutation.newBuilder()
        .addInsert(entity1)
        .addInsert(entity2))
    .build();  

These are slight variations on the examples given on these pages: https://cloud.google.com/datastore/docs/concepts/entities#Datastore_Retrieving_an_entity https://cloud.google.com/datastore/docs/concepts/entities#Datastore_Creating_an_entity

Cloud Datastore GQL does not currently support IN or writes.

Comments