Update document with pyarango

213 views Asked by At

I have an existing arango document that I get from a key:

doc = collection[key]

I used to update using:

for key, value in new_data.item():
    doc[key] = value
doc.save()

Sometime, new_data has an empty field and I want to remove this field from the doc.

I must miss something, since nothing I tried seems to work:

  • doc.patch(keep_null=True, **new_data)
  • doc.patch(keep_null=False, **new_data)
  • doc.set(new_data)
  • I tried with set() and getStore() too (when new_data is an arango doc)
  • I wanted to iterate on doc keys (using getStore), but I don't know how to delete a field from a doc...

How do I replace doc data by "new data" (which is an arango doc with same _key/_id)? Any help is appreciated!

1

There are 1 answers

0
Torsten Gang On

Was trying to figure out how to do this earlier today. What you need to do is

del arangodoc["key"]
arangodoc.save()#the save is important, patch won't delete the missing field.