gpt4 book ai didi

arangodb - 查询数组的 ArangoDB

转载 作者:行者123 更新时间:2023-12-04 14:12:06 26 4
gpt4 key购买 nike

我在 java 中查询 ArangoDB 以获取数组值时遇到问题。我尝试过使用 String[] 和 ArrayList,都没有成功。

我的查询:

FOR document IN documents FILTER @categoriesArray IN document.categories[*].title RETURN document

绑定(bind)参数:
Map<String, Object> bindVars = new MapBuilder().put("categoriesArray", categoriesArray).get();
categoriesArray包含一堆字符串。我不确定为什么它没有返回任何结果,因为如果我使用以下方式查询:
FOR document IN documents FILTER "Politics" IN document.categories[*].title RETURN document

我得到了我正在寻找的结果。只是在使用 Array 或 ArrayList 时不会。

我还尝试查询:
FOR document IN documents FILTER ["Politics","Law] IN document.categories[*].title RETURN document

为了模拟 ArrayList,但这不会返回任何结果。我会使用一堆单独的字符串进行查询,但是太多了,当使用这么长的字符串进行查询时,Java 驱动程序会出错。因此,我必须使用 Array 或 ArrayList 进行查询。

类别数组的示例:
["Politics", "Law", "Nature"]

数据库的示例图像:

enter image description here

最佳答案

Arango 也(现在)有 Array Comparison Operators允许搜索 ALL IN , ANY IN , 或 NONE IN

[ 1, 2, 3 ]  ALL IN  [ 2, 3, 4 ]  // false
[ 1, 2, 3 ] ALL IN [ 1, 2, 3 ] // true
[ 1, 2, 3 ] NONE IN [ 3 ] // false
[ 1, 2, 3 ] NONE IN [ 23, 42 ] // true
[ 1, 2, 3 ] ANY IN [ 4, 5, 6 ] // false
[ 1, 2, 3 ] ANY IN [ 1, 42 ] // true
[ 1, 2, 3 ] ANY == 2 // true
[ 1, 2, 3 ] ANY == 4 // false
[ 1, 2, 3 ] ANY > 0 // true
[ 1, 2, 3 ] ANY <= 1 // true
[ 1, 2, 3 ] NONE < 99 // false
[ 1, 2, 3 ] NONE > 10 // true
[ 1, 2, 3 ] ALL > 2 // false
[ 1, 2, 3 ] ALL > 0 // true
[ 1, 2, 3 ] ALL >= 3 // false
["foo", "bar"] ALL != "moo" // true
["foo", "bar"] NONE == "bar" // false
["foo", "bar"] ANY == "foo" // true

所以你现在可以过滤:
FOR document IN documents 
FILTER ["Politics", "Law] ANY IN (document.categories[*].title)[**]
RETURN document

关于arangodb - 查询数组的 ArangoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27936747/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com