0
votes

I'm just new to ArangoDB, so could you give me any tips how I can perform the following update?

I have the document collection, each document has a attribute seen. I want to update the existing collection from a csv-file in the following way: if in the file there is a line with _key that already is in the collection, I want to sum the seen value from csv-file and from the collection and replace the value in the collection by the sum; if there is no document with such _key, I just want to add it.

As far as I know, it is a little bit too much for the arangoimp tool, as it has an option either to replace or ignore dublicates.

How would you do that?

I would be grateful for any ideas.

1

1 Answers

3
votes

As you say, it's too much to ask from the arangoimp tool. You could use it to update existing records via _key and replace the seen attribute and create new documents it the _key does not exist yet. But it doesn't support to add logic that would sum up the seen values.

However, you can import your CSV with arangoimp to a temporary collection and use an AQL query to do that. Let temp be that temporary collection and coll your main collection:

FOR doc IN temp
  UPSERT { _key: doc._key }
  INSERT doc
  UPDATE { seen: OLD.seen + doc.seen }
  IN coll

You could optionally REPLACE instead of UPDATE or MERGE() the existing document with attributes from the imported document if needed, or remove the temp documents at the end.