简体   繁体   中英

How to query to more than one ancestor on google cloud datastore?

I need to retrieve objects than more than one ancestor. How can I retrieve it in only one query?

For example, retrieve all objects that has ancestor A or Ancestor B or ancestor C.

You cannot - you'd need to issue a separate query for each ancestor.

Workarounds

Depending on what you are trying to achieve, there are several methods to work around this limitation.

Note, all these workarounds would lose the "strong consistency" promise that is provided by ancestor queries, whereby results between entities in A, B, and C entity groups will not be strongly consistent.

1. Kindless Queries

If you are actually trying to query for all objects regardless of ancestor, you could issue a kindless query - in GQL this is SELECT *

2. Index a new Property

If you know the set of ancestors you need to query for in advanced, you could index a Boolean property when you initially write the entity. For example, create a new property called is_abc that is set to True if it has any of them as an ancestor. You can then use this property to query for all entities under those 3 entities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM