Search code examples
arangodbarangojs

Push/Pull Value(s) to Array in ArangoJS


I'm transitioning to ArangoDB for its power as a graph database and am struggling with the simple stuff.

If I have a document...

{ _id:'1234', tags:['apple','orange'] }

how can I update it to push or pull a value from the array? I would expect the syntax to be something like this, but didn't find anything in the docs...

collection.update({ _id:'1234' },{ tags:pull('mango') })
collection.update({ _id:'1234' },{ tags:push('avocado') })

Thank you!


Solution

  • You achieve this with AQL. For example

    FOR c in collection UPDATE c WITH { tags : PUSH(c.tags, 'avocado')} IN collection
    

    https://docs.arangodb.com/3.11/aql/high-level-operations/update/