ArangoDB

Cap Constraint

This is an introduction to ArangoDB's size restrictions aka cap for collections.



Cap Constraint

It is possible to restrict the size of collection. If you add a document and the size exceeds the limit, then the least recently created or updated document will be dropped.

Accessing Cap Constraints from the Shell


collection.ensureCapConstraint(size)
Creates a size restriction aka cap for the collection of size. If the restriction is in place and the (size plus one) document is added to the collection, then the least recently created or updated document is removed.

Note that at most one cap constraint is allowed per collection.

Note that the collection should be empty. Otherwise the behavior is undefined, i. e., it is undefined which documents will be removed first.

Note that this does not imply any restriction of the number of revisions of documents.

Examples

Restrict the number of document to at most 10 documents:

arango> db.examples.ensureCapConstraint(10);
{ "id" : "147879/934311", "type" : "cap", "size" : 10, "isNewlyCreated" : true }

arango> for (var i = 0;  i < 20;  ++i) { var d = db.examples.save( { n : i } ); }

arango> db.examples.count();
10