Oihana PHP Arango

aqlRemove.php

Table of Contents

Functions

aqlRemove()  : string
Remove one or multiple documents from a collection using an AQL `REMOVE` operation.

Functions

aqlRemove()

Remove one or multiple documents from a collection using an AQL `REMOVE` operation.

aqlRemove([array{collection?: ?string, expression?: ?string, key?: ?string, options?: ?array{exclusive?: bool, ignoreErrors?: bool, ignoreRevs?: bool, refillIndexCaches?: bool, waitForSync?: bool}} $init = [] ]) : string

This helper builds a valid AQL query string for removing documents based on either:

  • a custom key expression, or
  • a document key (_key) and an optional document prefix (defaults to doc).

AQL syntax:

REMOVE <keyExpression> IN <collection> [OPTIONS {...}]
Parameters
$init : array{collection?: ?string, expression?: ?string, key?: ?string, options?: ?array{exclusive?: bool, ignoreErrors?: bool, ignoreRevs?: bool, refillIndexCaches?: bool, waitForSync?: bool}} = []

Initial options array.

  • 'collection' : The name of the collection in which the document should be updated. By default, if the argument is null, use @@collection bindVars definition.
  • 'expression' : The key expression that contains the document identification. If the expression is null or an empty string, the 'key' and 'prefix' definitions are used.
  • 'key' : The unique identifier of the document to remove. By default _key -> REMOVE doc._key IN ...
  • 'options' : Build a RemoveOptions definition to inject at the end of the query.
  • 'prefix' : Optional The name of the document reference. By default doc -> REMOVE doc._key IN ...
Tags
throws
InvalidArgumentException

If the collection name is missing.

ReflectionException

If a reflection error occurs while building options.

UnsupportedOperationException

If the operation is not supported.

example

Example usage:

Basic removal by document key:

echo $this->remove([ 'collection' => 'users', 'key' => '_key' ]);
// "REMOVE {_key:doc._key} IN users"

Using a custom key expression:

echo $this->remove
([
    'collection' => 'products',
    'expression' => 'item._key'
]);
// "REMOVE item._key IN products"

With options

echo $this->remove
([
    'collection' => 'logs',
    'options'    =>
    [
        'ignoreErrors'      => true ,
        'waitForSync'       => false ,
        'refillIndexCaches' => true ,
    ]
]);
// "REMOVE {_key:doc._key} IN logs OPTIONS { ignoreErrors: true, waitForSync: false, refillIndexCaches: true }"
see
https://docs.arangodb.com/stable/aql/high-level-operations/remove
author

Marc Alcaraz

since
1.0.0
Return values
string

The compiled AQL REMOVE statement.

On this page

Search results