[英]How to replace list element in arangodb
I have a list in arango collection like below我在 arango 集合中有一个列表,如下所示
{
"id":"123"
"studentlist": [
"a",
"b",
"c"
]
}
Now based on some filter condition i have to replace particular element of list with the replacement set.现在基于一些过滤条件,我必须用替换集替换列表的特定元素。 In this example i want to replace b with [b1,b2], so that my collection should look like below在这个例子中,我想用 [b1,b2] 替换 b,这样我的集合应该如下所示
{
"id":"123"
"studentlist": [
"a",
"b1",
"b2",
"c"
]
}
how to do it using arango query.如何使用 arango 查询做到这一点。
You can replace "studentlist" as the whole list.您可以将“studentlist”替换为整个列表。
UPDATE "<document_key>" WITH {
"studentlist": [
"a",
"b1",
"b2",
"c"
]
} IN <collection_name>
You have a lot of functions at your disposal to manipulate the data, eg using the array-modifying REMOVE_VALUE
, APPEND
and SORTED
I massage the studentlist
of the original data, and use the object-modifying MERGE
to return the desired result.您在您的处置有很多的功能,使用阵列修改操作数据,如REMOVE_VALUE
, APPEND
和SORTED
我按摩studentlist
的原始数据,并使用修改对象的MERGE
返回所需的结果。
LET data = {
"id":"123",
"studentlist": [
"a",
"b",
"c"
]
}
LET list = SORTED(APPEND(REMOVE_VALUE(data.studentlist, "b"), ["b1", "b2"]))
RETURN MERGE(data, {studentlist: list})
Returns your desired返回您想要的
[
{
"id": "123",
"studentlist": [
"a",
"b1",
"b2",
"c"
]
}
]
as single element of the result list.作为结果列表的单个元素。 This should get you started.这应该让你开始。 You can use LET
expressions in FOR
queries, you can use sub-queries to assemble data, and so on... And then use @Ömer_Taban's answer to update the documents, eg你可以在FOR
查询中使用LET
表达式,你可以使用子查询来组装数据等等......然后使用@Ömer_Taban 的答案来更新文档,例如
FOR d IN data
FILTER <YOUR_CONDITIONS>
LET list...
...
UPDATE d WITH list IN data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.