'How to update a document with new attribute

I'm using ArangoDB in order to update a document with a new attribute.

My steps are as follows:

  1. Get the document and store it in a variable

    doc = self.db.get_document(document_name="document_name")

  2. Iterate over the doc, and add to it the attribute, for e.g.:

         for idx, movie in enumerate(doc):
    
             print(movie)
    
             query = 'UPSERT { movie_id: @movie_id, scene_element: @scene_element}  INSERT\
                 { movie_id: @movie_id, scene_element: @scene_element, index: @index, \
                     _key: @_key, _id: @_id, _rev: @_rev, url_path: @url_path, captions: @captions, ref: @ref, \
                     experts: @experts, groundtruth: @groundtruth, base: @base, source: @source, File: @File } UPDATE \
                 {   index: @index \
                 } IN document_name'
    
             movie["index"] = idx
             self.pdb.aql.execute(query, bind_vars=movie)
    

And this works, I'm trying to use this query differently without the INSERT command. Why something like this doesn't work:

query = 'UPSERT { movie_id: @movie_id, scene_element: @scene_element}  UPDATE \
                    {   index: @index \
                    } IN document_name'

Finding the correct movie_id and scene_element, and just updating it with new index.

The error I'm getting is invalid syntax, and it asks for me to put the INSERT command.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source