multiple filters vs OR , ndb query

泪湿孤枕 提交于 2019-12-07 15:09:52

问题


What is the difference between these queries:

  1. With consequent filters:

    qry1 = Account.query() # Retrieve all Account entitites
    qry2 = qry1.filter(Account.userid >= 40) # Filter on userid >= 40
    qry3 = qry2.filter(Account.userid < 50) # Filter on userid < 50 as well
    
  2. Using ndb.OR:

    qry = Article.query(ndb.OR(Account.userid >= 40,
                           Account.userid < 50))
    
  3. Using ndb.AND:

    qry = Article.query(ndb.AND(Account.userid >= 40,
                            Account.userid < 50))
    

回答1:


The first query does an AND. Thus, only the entities that match both inequalities will be returned by the query. The second query does an OR. Thus, entities that match either of the filters will be returned. For more information about ndb queries, take a look at NDB Queries.




回答2:


Third and the First query are exactly identical. But the second query is absurd, it may end up returning all Entities in the Kind.



来源:https://stackoverflow.com/questions/26438435/multiple-filters-vs-or-ndb-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!