ndb 投影查询 return 不正确的实体数

ndb projection query return incorrect number of entities

我的 TwAccount 是

class TwAccount(ndb.Model):

   100 different properties here
   error = ndb.IntegerProperty(repeated=True)

我试试:

twaccount_dbs = model.TwAccount.query().filter(ndb.GenericProperty('followuserfollowme') == True)

它 returns 1 个实体

但是我只想查询1属性.

twaccount_dbs = model.TwAccount.query().filter(ndb.GenericProperty('followuserfollowme') == True).fetch(projection=["error"])

然后它 returns 0 个实体。

我试试

twaccount_dbs = model.TwAccount.query().filter(ndb.GenericProperty('followuserfollowme') == True).fetch(projection=[model.TwAccount.error])

但它也 returns 0 个实体

我希望它 return 有 1 个实体。

更新 1: 我发现如果错误是一个空值(因此不存在),那么投影查询将 return 0

我的objective是查询TwAccount中的所有实体。如果错误为空,则执行 deferred.defer(function,entity_key).

我想使用投影查询来节省阅读成本。不可能吗?

很遗憾,您无法通过 unset/empty 属性:

筛选查询结果

来自Index definition and structure

An entity is included in the index only if it has an indexed value set for every property used in the index; if the index definition refers to a property for which the entity has no value, that entity will not appear in the index and hence will never be returned as a result for any query based on the index.

另见相关内容AppEngine: Query datastore for records with <missing> value