Quick Tipp for First-Time Users of The ArangoDb Python Client

I started to play around with ArangoDB and used Python to get some data into my first database. Long story short: if you want to set your own key for the documents, do it on the document, not on the initialization data. EDIT: this is only true for the most recent version 1.3.1 release on pypi by the time of writing ((See conversation on github for details)). After setting up the connection with something like
from pyArango.connection import Connection
import os

connection = Connection(
**DO NOT** do
json_data = {'foo': 'bar'}
json_data['_key'] = 'your_key'
doc = connection['your_database']['your_collection'].createDocument(initValues=json_data)
but **DO**
json_data = {'foo': 'bar'}
doc = connection['your_database']['your_collection'].createDocument(initValues=json_data)
doc._key = 'your_key'
In the first case, the _key attribute is just ignored and the database creates a key automatically. The rational behind this probably is, that ArangoDB client should ignore all attributes that start with an underscore because they are used internally. EDIT: I seemed to have been wrong. The intended behavior seems to always have been to set the key attribute even in the first of the two code samples above. More recent (currently unreleased) versions fixes this issue.

Leave a Reply

Your email address will not be published. Required fields are marked *