如何 return 与列表中的项目匹配的 arangodb 文档列表?
How to return a list of arangodb documents that match an item in a list?
使用 python 和 AQL 我正在尝试 return 匹配给定列表中任何项目的顶点列表。我得到的数据库的当前结果是一个空列表。
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
)
您应该使用 IN
运算符:
FOR doc IN some_collection
FILTER doc.name IN @list_of_terms
RETURN doc
来自文档:
IN
: test if a value is contained in an array
见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
)
使用 python 和 AQL 我正在尝试 return 匹配给定列表中任何项目的顶点列表。我得到的数据库的当前结果是一个空列表。
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
)
您应该使用 IN
运算符:
FOR doc IN some_collection
FILTER doc.name IN @list_of_terms
RETURN doc
来自文档:
IN
: test if a value is contained in an array
见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
)