Documents in ArangoDB are JSON objects. These objects can be nested (to any depth) and may contains lists. Each document is unique identified by its document handle.
Usage example:
from arango import create
# connection & collection `test`
c = create()
c.test.create()
# create FROM document
document = c.test.documents.create({
"sample_key": "sample_value"
})
assert document.get("sample_key") == "sample_value"
assert c.test.documents().count != 0
Documents are accessible via collection instance for example connection.collection.sample_collection.documents. Usually this expressions looks lot shorter.
Basically via docuemnts shortcut accessible Docuemnts Proxy - Proxy object which have several shortcuts and produce Resultset object.
Below described basic method within Documents proxy:
Proxy object to handle work with documents within collection instance
Shortcut for new documents creation
Delete document shorcut
ref_or_document may be either plai reference or Document instance
Update document
ref_or_document may be either plain reference or Document instance
Get count of all documents in Collection
Load particular document by id doc_id.
Example:
doc_id = c.test.documents.create({"x": 2}).id
doc = c.test.documents.load(doc_id)
assert doc.body["x"] == 2
Document instance methods consist from basic CRUD methods and serveral shortcuts to more convenient work with documents.
Particular instance of Document
Method to create new document.
Possible arguments: waitForSync
Read more about additional arguments Documents REST Api
This method may raise DocumentAlreadyCreated exception in case document already created.
Return document instance (self) or None
Method to update document.
This method is NOT for overwriting document body. In case document is list it will extend current document body. In case it’s dict - update document body with new data.
To overwrite document body use body setter.
In case save argument set to False document will not be updated until save() method will be called.
This method may raise EdgeNotYetCreated exception in case you trying to update edge which is not saved yet.
Exception DocumentIncompatibleDataType will be raised in case body of the document isn’t either dict or list.
Delete current document.
Return True if success and False if not
Method to force save of the document.
kwargs will be passed directly to requests arguments.
Return whole document.
This property setter also should be used if overwriting of whole document is required.
doc_id = c.test.documents.create({"x": 2}).id
doc = c.test.documents.load(doc_id)
assert doc.body["x"] == 2
doc.body = {"x": 1}
doc.save()
assert c.test.documents.load(doc_id).body["x"] == 1
This method very similar to dict‘s get method. The difference is that default value should be specified explicitly.
To get specific value for specific key in body use and default (fallback) value 0
c.test.documents().first.get(name="sample_key", default=0)