如何返回与列表中的项匹配的arangodb文档列表?

46qrfjad  于 2022-12-09  发布在  Go
关注(0)|答案(1)|浏览(151)

使用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

和full函数使用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
    )
u91tlkcl

u91tlkcl1#

您应该使用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
)

相关问题