ArangoDB v2.8 reached End of Life (EOL) and is no longer supported.

This documentation is outdated. Please see the most recent version here: Try latest

Working with Cap Constraints

Create cap constraint

creates a cap constraint

POST /_api/index#CapConstraints

Query Parameters

  • collection (required): The collection name.
    A JSON object with these properties is required:

  • type: must be equal to “cap”.

  • size: The maximal number of documents for the collection. If specified, the value must be greater than zero.

  • byteSize: The maximal size of the active document data in the collection (in bytes). If specified, the value must be at least 16384.

NOTE Swagger examples won’t work due to the anchor.


Creates a cap constraint for the collection collection-name, if it does not already exist. Expects an object containing the index details.
Note: The cap constraint does not index particular attributes of the documents in a collection, but limits the number of documents in the collection to a maximum value. The cap constraint thus does not support attribute names specified in the fields attribute nor uniqueness of any kind via the unique attribute.
It is allowed to specify either size or byteSize, or both at the same time. If both are specified, then the automatic document removal will be triggered by the first non-met constraint.

Return codes

  • 200: If the index already exists, then an HTTP 200 is returned.

  • 201: If the index does not already exist and could be created, then an HTTP 201 is returned.

  • 400: If either size or byteSize contain invalid values, then an HTTP 400 is returned.

  • 404: If the collection-name is unknown, then a HTTP 404 is returned.

Examples
Creating a cap constraint

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/index?collection=products <<EOF
{ 
  "type" : "cap", 
  "size" : 10 
}
EOF

HTTP/1.1 201 Created
content-type: application/json; charset=utf-8

show response body