Sjuul Janssen
Sjuul Janssen

Reputation: 1812

Google Cloud Datastore get entities by list of keys

I have a set of entities which I want to retrieve from GCD. Some (or most) entities, however, I already have loaded in memory. So my approach was first to find out which keys existed. So I did a ancestor query with a projection for __key__

I figured all I had to do was filter out which keys I still needed to load and do something equivalent to ndb.get_multi I couldn't find anything similar in the documentation. Perhaps I missed it?

I will potentially have hundreds of relatively large entities for the same ancestor query. Only retrieving the right entities would make the difference between getting only a handful or all of them.

TLDR: I am looking for an equivalent of ndb.get_multi

Upvotes: 0

Views: 717

Answers (1)

Ed Davisson
Ed Davisson

Reputation: 2927

The Lookup method supports fetching multiple keys:

req = datastore.LookupRequest()
req.key.extend([key1, key2])
resp = datastore.lookup(req)

Upvotes: 1

Related Questions