Collections

Collections are something similar to tables in SQL databases world. A Collection is a group of documents and Edges.

It’s quite easy to create collection:

from arango import create

# here we define connection to Arango
c = create(db="test")

# make sure database exists
c.database.create()

# here we creating collection explicitly
c.test.create()

assert len(c.collections()) == 1

# here we creating edges collection
c.test_edges.create_edges()

assert len(c.collections()) == 2

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)

Get list of collections

To get list of Collections simply call connection like c()

For example:

# here we are creating collection explicitly
c.test.create()

assert c(), ["test"]
class arango.collection.Collections(connection)

connection) for Collections

__call__(*args, **kwargs)

Return list of collections within current database

__getattr__(name)

Accessible as property by default.

__getitem__(name)

In case property used internally by Collections it’s possible to use dict-like interface, for example .database used internally as link to database instance but feel free to use dict-like interface to create collection with name database: voca["database"]

Collection

Arango DB provide rich API to manipulate collections Collection instance methods are quite rich. Here is documentation which describes Collections REST Api

class arango.collection.Collection(connection=None, name=None, id=None, createCollection=True, response=None)

Represent single collection with certain name

__len__()

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)
cid

Get collection name

count()

Get count of all documents in collection

create(waitForSync=False, type=2, **kwargs)

Create new Collection. You can specify waitForSync argument (boolean) to wait until collection will be synced to disk

create_edges(*args, **kwargs)

Create new Edges Collection - sepcial kind of collections to keep information about edges.

delete()

Delete collection

documents

Get Documents related to Collection.

Technically return instance of Documents for Collection instance object

edges

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

index

Get Indexes related to Collection

info(resource='')

Get information about collection. Information returns AS IS as raw Response data

load()

Load collection into memory

properties(**props)

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

query

Create Query Builder for current collection.

c.test.create()
c.test.docs.create({"name": "sample"})

assert len(c.test.query.execute()), 1
rename(name=None)

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()

Truncate current Collection

unload()

Unload collection from memory