AQL - Array manipulation of a document - how to?

31 views
Skip to first unread message

Martin Kuhn

unread,
Mar 30, 2016, 1:58:53 AM3/30/16
to ArangoDB
I would like to manipulate array entries in a document:

e.g. I have simple items in the following structure

  "name": "MyName", 
  "tags": ["Tag1", "Tag2", "Tag3"]
}


Now I want to change the tag "Tag1" with "Tag11". 

How is this accomplishable with AQL?

How would I delete one of the tags?

TIA



Wilfried Gösgens

unread,
Mar 30, 2016, 6:37:31 AM3/30/16
to ArangoDB
Hi Martin,
this can be achieved using the MINUS function ( https://docs.arangodb.com/Aql/ArrayFunctions.html )

db._query('RETURN MINUS([1,3,5,7], [3])').toArray()


Combining it with PUSH to insert the new value:

db._query('FOR item IN test UPDATE item WITH {tags: MINUS(PUSH(item.tags, "Tag11"), ["Tag1"])} IN test')

resulting in the document you wanted.

Martin Kuhn

unread,
Mar 30, 2016, 7:38:51 AM3/30/16
to ArangoDB
Very cool, thank you
Reply all
Reply to author
Forward
0 new messages