首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何返回与列表中某一项相匹配的arangodb文档列表?

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

Stack Overflow用户
提问于 2020-08-05 00:18:36
回答 1查看 545关注 0票数 0

使用python和AQL,我试图返回与给定列表中任何项匹配的顶点列表。我正在获得的db的当前结果是一个空列表。

python的等价物是:

代码语言:javascript
复制
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查询的例子。

代码语言:javascript
复制
For doc in some_collection
    FILTER doc.name==@list_of_terms
    RETURN doc

以及使用python-arango实现的全部功能

代码语言:javascript
复制
bind_vars = {
    "lookup_terms": list_of_terms
   } 

提前感谢

代码语言:javascript
复制
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
    )
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-06 09:58:39

您应该使用IN操作符:

代码语言:javascript
复制
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代码将变成:

代码语言:javascript
复制
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
)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63256722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档