python - 如何返回与列表中的项目匹配的 arangodb 文档列表?
问题描述
使用 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
)
解决方案
您应该使用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
)
推荐阅读
- android - 滚动到recyclerview android中的特定视图类型
- javascript - 如何使用 JS 触发下载音频链接,而无需浏览器导航到新页面?
- r - 使用 R 命令 dnorm 查找计数的期望值
- laravel - 如何在 Laravel Vue 设置中使用作用域插槽来类绑定
- php - 检测 fastCGI 是否在远程服务器上运行
- kubernetes - 无法连接到 Kafka 无头服务
- kurento - Kurento Media Server:服务在启动后立即停止
- php - VSCode 没有按照 php.ini 显示 DOCUMENT_ROOT
- javascript - 当我在我的购物篮中删除多个产品时,只有第一个产品数量返回我的数据库,其他产品数量没有返回
- django-rest-framework - Django Restframework dj-rest-auth 密码重置确认提交问题