The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

ArangoDB::Collection - An ArangoDB collection

DESCRIPTION

A instance of ArangoDB collection.

METHODS FOR COLLECTION HANDLING

new($connection, $collection_info)

Constructor.

id()

Returns identifer of the collection.

status()

Returns status of the collection.

name([$name])

Returns name of collection. If $name is set, rename the collection.

count()

Returns number of documents in the collection.

drop()

Drop the collection.

truncate()

Truncate the collection.

load()

Load the collection.

unload()

Unload the collection.

is_newborn()

Return true if status of the collection is 'new born'.

is_unloaded()

Return true if status of the collection is 'unloaded'.

is_loaded()

Return true if status of the collection is 'loaded'.

is_being_unloaded()

Return true if status of the collection is 'being unloaded'.

is_deleted()

Return true if status of the collection is 'deleted'.

is_corrupted()

Return true if status of the collection is invalid.

figure($type)

Returns number of documents and additional statistical information about the collection.

$type is key name of figures.The key names are:

count

The number of documents inside the collection.

alive-count

The number of living documents.

alive-size

The total size in bytes used by all living documents.

dead-count

The number of dead documents.

dead-size

The total size in bytes used by all dead documents.

dead-deletion

The total number of deletion markers.

datafiles-count

The number of active datafiles.

datafiles-fileSize

The total filesize of datafiles.

journals-count

The number of journal files.

journals-fileSize

The total filesize of journal files.

journalSize

The maximal size of the journal in bytes.

wait_for_sync($boolean)

Set or get the property 'wait_for_sync' of the collection.

METHODS FOR DOCUMENT HANDLING

save($data)

Save document to the collection. Returns instance of ArangoDB::Document.

    $collection->save( { name => 'John' } );

bulk_import($header,$body)

Import multiple documents at once.

$header

attribute names(ARRAY reference).

$body

document values(ARRAY reference).

Example:

    $collection->bulk_import(
        [qw/fistsName lastName age gender/],
        [
            [ "Joe", "Public", 42, "male" ],
            [ "Jane", "Doe", 31, "female" ],
        ]
    );    

bulk_import_self_contained($documents)

Import multiple self-contained documents at once.

$documents is the ARRAY reference of documents.

Example:

    $collection->bulk_import_self_contained( [ 
        { name => 'foo', age => 20 }, 
        { type => 'bar', count => 100 }, 
    ] );

METHODS FOR EDGE HANDLING

save_edge($from,$to[,$data])

Save edge to the collection. Returns instance of ArangoDB::Edge.

$from

The document that start-point of the edge.

$to

The document that end-point of the edge.

$data

Document data.

    $collection->save_edge($document1,$document2, { rel => 'has-a' });

METHODS FOR SIMPLE QUERY HANDLING

all([$options])

Send 'all' simple query. Returns instance of ArangoDB::Cursor.

This will return all documents of in the collection.

    my $cursor = $collection->all({ limit => 100 });

$options is query option(HASH reference).The attributes of $options are:

limit

The maximal amount of documents to return. (optional)

skip

The documents to skip in the query. (optional)

by_example($example[,$options])

Send 'by_example' simple query. Returns instance of ArangoDB::Cursor.

This will find all documents matching a given example.

    my $cursor = $collection->by_example({ age => 20 });
$example

The exmaple.

$options

Query option(HASH reference).The attributes of $options are:

limit

The maximal amount of documents to return. (optional)

skip

The documents to skip in the query. (optional)

first_example($example)

Send 'first_example' simple query. Returns instance of ArangoDB::Document.

This will return the first document matching a given example.

$example is the exmaple.

    my $document = $collection->by_example({ age => 20 });

range($attr,$lower,$upper[,$options])

Send 'range' simple query. Returns instance of ArangoDB::Cursor.

It looks for documents in the collection with attribute between two values.

Note: You must declare a skip-list index on the attribute in order to be able to use a range query.

    my $cursor = $collection->range('age', 20, 29, { closed => 1 } );
$attr

The attribute path to check.

$lower

The lower bound.

$upper

The upper bound.

$options

Query option(HASH reference).The attributes of $options are:

closed

If true, use intervall including $lower and $upper, otherwise exclude $upper, but include $lower

limit

The maximal amount of documents to return. (optional)

skip

The documents to skip in the query. (optional)

near($latitude,$longitude[,$options])

Send 'near' simple query. Returns instance of ArangoDB::Cursor.

The default will find at most 100 documents near a given coordinate. The returned list is sorted according to the distance, with the nearest document coming first.

    $cursor = $collection->near(0,0, { limit => 20 } );
$latitude

The latitude of the coordinate.

$longitude

The longitude of the coordinate.

$options

Query option(HASH reference).The attributes of $options are:

distance

If given, the attribute key used to store the distance to document(optional).

distance is the distance between the given point and the document in meter.

limit

The maximal amount of documents to return. (optional)

skip

The documents to skip in the query. (optional)

geo

If given, the identifier of the geo-index to use. (optional)

within($latitude,$longitude,$radius[,$options])

Send 'within' simple query. Returns instance of ArangoDB::Cursor.

This will find all documents with in a given radius around the coordinate (latitude, longitude). The returned list is sorted by distance.

    $cursor = $collection->within(0,0, 10 * 1000, { distance => 'distance' } );
$latitude

The latitude of the coordinate.

$longitude

The longitude of the coordinate.

$radius

The maximal radius(meter).

$options

Query option(HASH reference).The attributes of $options are:

distance

If given, the attribute name used to store the distance to document(optional).

distance is the distance between the given point and the document in meter.

limit

The maximal amount of documents to return. (optional)

skip

The documents to skip in the query. (optional)

geo

If given, the identifier of the geo-index to use. (optional)

METHODS FOR INDEX HANDLING

ensure_hash_index($fileds)

Create hash index for the collection. Returns instance of ArangoDB::Index::Hash.

This hash is then used in queries to locate documents in O(1) operations.

$fileds is the field of index.

    $collection->ensure_hash_index([qw/user.name/]);
    $collection->save({ user => { name => 'John', age => 42,  } });

ensure_unique_constraint($fileds)

Create unique hash index for the collection. Returns instance of ArangoDB::Index::Hash.

This hash is then used in queries to locate documents in O(1) operations. If using unique hash index then no two documents are allowed to have the same set of attribute values.

$fileds is the field of index.

ensure_skiplist($fileds)

Create skip-list index for the collection. Returns instance of ArangoDB::Index::SkipList.

This skip-list is then used in queries to locate documents within a given range.

$fileds is the field of index.

    $collection->ensure_skiplist([qw/user.age/]);
    $collection->save({ user => { name => 'John', age => 42 } });

ensure_unique_skiplist($fileds)

Create unique skip-list index for the collection. Returns instance of ArangoDB::Index::SkipList.

This skip-list is then used in queries to locate documents within a given range. If using unique skip-list then no two documents are allowed to have the same set of attribute values.

$fileds is the field of index.

ensure_geo_index($fileds[,$is_geojson])

Create geo index for the collection. Returns instance of ArangoDB::Index::Geo.

$fileds

The field of index.

$is_geojson

Boolean flag. If it is true, then the order within the list is longitude followed by latitude.

Create an geo index for a list attribute:

    $collection->ensure_geo_index( [qw/loc/] );
    $collection->save({ loc => [0 ,0] });

Create an geo index for a hash array attribute:

    $collection->ensure_geo_index( [qw/location.latitude location.longitude/] );
    $collection->save({ location => { latitude => 0, longitude => 0 } }); 

ensure_geo_constraint($fileds[,$ignore_null])

It works like ensure_geo_index() but requires that the documents contain a valid geo definition. Returns instance of ArangoDB::Index::Geo.

$fileds

The field of index.

$ignore_null

Boolean flag. If it is true, then documents with a null in location or at least one null in latitude or longitude are ignored.

ensure_cap_constraint($size)

Create cap constraint for the collection.Returns instance of ArangoDB::Index::CapConstraint.

It is possible to restrict the size of collection.

$size is the maximal number of documents.

Restrict the number of document to at most 100 documents:

    $collection->ensure_cap_constraint(100);

get_indexes()

Returns list of indexes of the collection.

AUTHOR

Hideaki Ohno <hide.o.j55 {at} gmail.com>