简体   繁体   English

如何通过ID ndb.query设置过滤

[英]How to set filtering by ID ndb.query

I try filtering ID such as the following 我尝试过滤如下的ID

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. 但是,我在ndb.query参考中找不到按ID进行过滤。

I can filter by key.But It's needed ancestor key(id). 我可以按键过滤。但这是祖先键(id)。 I want to fetch crossing entity group. 我想获取交叉实体组。

How to filter by ID with ndb.query? 如何使用ndb.query按ID过滤?

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 合并上述所有已执行查询的结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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