Collections is something similar to tables in SQL databases world. Collection consist from documents and Edges.
It’s quite easy to create collection:
from arango import create
# here we define connection to Arango
c = create()
# here we creating collection explicitly
c.test.create()
assert len(c.collections()) == 1
Collection test being created.
Note
It’s not necessary to create collection before adding documents to it. You can specify createCollection as keyed argument during creation of new Document
If you don’t want to create collection explicitly use
# here we creating document AND collection
c.test.documents.create({"sample": 1}, createCollection=True)
To get list of Collections simply call connection like c()
For example:
# here we creating collection explicitly
c.test.create()
assert c(), ["test"]
Arango DB provide rich API to manipulate collections Collection instance methods is quite rich. Here is documentation which describe Collections REST Api
Represent single collection with certain name
Exactly the same as count but it’s possible to use in more convenient way
c.test.create()
assert c.test.count() == len(c.test)
Get collection name
Get count of all documents in collection
Create new Collection. You can specify waitForSync argument (boolean) to wait until collection will be synced to disk
Delete collection
Get Documents related to Collection.
Technically return instance of Documents for Collection instance object
Get Edges related to Collection.
Technically return instance of Edges for Collection instance object
If this method used to query edges (or called with no arguments) it may generated exceptions:
DocumentIncompatibleDataType
In case you’re not provided VERTEX of the Edge which should be instance or subclass od Document
More about DocumentIncompatibleDataType
Get Indexes related to Collection
Get information about collection. Information returns AS IS as raw Response data
Load collection into memory
Set or get collection properties.
If **props are empty eq no keyed arguments specified then this method return properties for current Collection.
Otherwise method will set or update properties using values from **props
Create Query Builder for current collection.
c.test.create()
c.test.docs.create({"name": "sample"})
assert len(c.test.query.execute()), 1
Change name of Collection to name.
Return value is bool if success or error respectively.
This method may raise exceptions:
InvalidCollection
This one may be generated only in case very low-level instantiation of Collection and if base collection proxy isn’t provided More about InvalidCollection
CollectionIdAlreadyExist
If Collection with new name already exist this exception will be generated. More about CollectionIdAlreadyExist
InvalidCollectionId
If Collection instantiated but name is not defined or not set. More about InvalidCollectionId
Sample usage:
c.test.create()
c.test.rename("test2")
assert "test2" in c()
Truncate current Collection
Unload collection from memory