Collections

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)

Get list of collections

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

For example:

# here we 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

Collection

Arango DB provide rich API to manipulate collections Collection instance methods is quite rich. Here is documentation which describe 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 None

Get collection name

count()

Get count of all documents in collection

create(waitForSync=False, **kwargs)

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

delete()

Delete collection

documents None

Get Documents related to Collection.

Technically return instance of Documents for Collection instance object

edges None

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:

index None

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 None

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

Table Of Contents

Related Topics

This Page

Fork me on GitHub