【问题标题】:How to return a list of arangodb documents that match an item in a list?如何返回与列表中的项目匹配的 arangodb 文档列表?
【发布时间】:2020-08-05 00:18:36
【问题描述】:

使用 python 和 AQL,我试图返回与给定列表中的任何项目匹配的顶点列表。我得到的数据库的当前结果是一个空列表。

python 等价物是这样的:

list_of_terms = ["yellow", "blue"]
list_of_vertices = ["yellow", "green"]

terms = [term for term in list_of_terms if term in list_of_vertices]

print(terms)

我尝试的一个 AQL 查询示例。

For doc in some_collection
    FILTER doc.name==@list_of_terms
    RETURN doc

以及使用python-arango的完整功能

bind_vars = {
    "lookup_terms": list_of_terms
   } 

提前致谢

qry = "FOR doc IN `{0}` FILTER doc.name== @lookup_terms AND doc.text != null RETURN doc".format(collection_nm)
print(qry)
cursor = db.aql.execute(
    qry,
    bind_vars=bind_vars,
    batch_size=10,
    count=True
    )

【问题讨论】:

    标签: python arangodb aql


    【解决方案1】:

    您应该使用IN 运算符:

    FOR doc IN some_collection
        FILTER doc.name IN @list_of_terms
        RETURN doc
    

    来自文档:

    IN: 测试一个值是否包含在数组中

    https://www.arangodb.com/docs/stable/aql/operators.html#range-operator

    你的 python 代码会变成:

    bind_vars = {
        "lookup_terms": list_of_terms
    } 
    qry = "FOR doc IN `{0}` FILTER doc.name IN @lookup_terms AND doc.text != null RETURN doc".format(collection_nm)
    print(qry)
    cursor = db.aql.execute(
        qry,
        bind_vars=bind_vars,
        batch_size=10,
        count=True
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 2020-12-19
      • 2020-06-07
      • 2020-05-27
      • 2015-05-25
      • 1970-01-01
      相关资源
      最近更新 更多