stack_user
stack_user

Reputation: 595

How to set filtering by ID ndb.query

I try filtering ID such as the following

ancestorid  id      value
1111       aaaa     10       // I want to fetch this
1111       bbbb     20
2222       aaaa     30       // and this.
2222       cccc     40

but, I cannot find filtering by id in ndb.query reference.

I can filter by key.But It's needed ancestor key(id). I want to fetch crossing entity group.

How to filter by ID with ndb.query?

Upvotes: 0

Views: 269

Answers (1)

Dan Cornilescu
Dan Cornilescu

Reputation: 39824

You can't do that with a single query. That's because if you make an ancestor query you'll only get results from that ancestor entity group and if you don't make an ancestor query you'll only get entities which have no ancestors. All these queries would have non-overlapping results.

The only way to obtain the results you want would be with multiple queries:

  • get the ancestor keys of interest (possibly using a query)
  • perform one ancestor query for each obtained ancestor key
  • perform a non-ancestor query as well, if the entities you seek might not have an ancestor
  • combine the results from all the performed queries mentioned above

Upvotes: 2

Related Questions