代码之家  ›  专栏  ›  技术社区  ›  John

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

  •  1
  • John  · 技术社区  · 6 年前

    我的账户是

    class TwAccount(ndb.Model):
    
       100 different properties here
       error = ndb.IntegerProperty(repeated=True)
    

    我试着:

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

    但我只想查询一个属性。

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

    然后返回0个实体。

    我试过了

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

    但它也返回0个实体

    我希望它返回一个实体。

    更新1: 我发现如果错误是emtpy(所以不存在),那么投影查询将返回0

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

    1 回复  |  直到 6 年前
        1
  •  1
  •   Dan Cornilescu    6 年前

    很遗憾,您无法按未设置/空属性筛选查询结果:

    Index definition and structure :

    只有当实体具有索引值集时,它才包含在索引中 出现在索引中,因此不会返回

    AppEngine: Query datastore for records with <missing> value