documents
Table of Contents
Functions
- attributes() : string
- Return the attribute keys of a document.
- count() : string
- Return the number of attribute keys of a document (an alias of {@see length()} / `LENGTH()`).
- entries() : string
- Return the attributes of a document as an array of key/value pairs.
- has() : string
- Returns an AQL expression to test whether an attribute exists in a document.
- isSameCollection() : string
- Test whether a document identifier belongs to a given collection.
- keep() : string
- Keep only the given top-level attributes of a document.
- keepRecursive() : string
- Keep only the given attributes of a document, recursing into sub-documents.
- keys() : string
- Return the attribute keys of a document (an alias of {@see attributes()} / `ATTRIBUTES()`).
- length() : string
- Return the number of attribute keys of a document.
- matches() : string
- Test whether a document matches one of the given example documents.
- merge() : string
- Merge multiple documents into a single document.
- mergeRecursive() : string
- Recursively merge multiple documents into a single document.
- parseCollection() : string
- Return the collection name part of a document identifier.
- parseIdentifier() : string
- Return the collection name and key of a document identifier as an object.
- parseKey() : string
- Return the key part of a document identifier.
- translate() : string
- Look up the specified value in a lookup document and return the mapped value.
- unsetAttributes() : string
- Remove the given top-level attributes from a document.
- unsetRecursive() : string
- Remove the given attributes from a document, recursing into sub-documents.
- value() : string
- Extract a value from a document at the specified path.
- values() : string
- Return the attribute values of a document.
- zip() : string
- Build a document from an array of attribute keys and an array of values.
Functions
attributes()
Return the attribute keys of a document.
attributes(string $document[, bool|null $removeSystemAttrs = null ][, bool|null $sort = null ]) : string
Wraps the ArangoDB AQL function ATTRIBUTES(document, removeSystemAttrs, sort)
(also aliased as KEYS()).
Example AQL usage:
ATTRIBUTES({b: 2, _key: "x", a: 1}) // returns ["b", "_key", "a"]
ATTRIBUTES({b: 2, _key: "x", a: 1}, true) // returns ["b", "a"]
ATTRIBUTES({b: 2, _key: "x", a: 1}, true, true) // returns ["a", "b"]
Parameters
- $document : string
-
The document variable or expression.
- $removeSystemAttrs : bool|null = null
-
Whether to omit system attributes (
_id,_key,_rev, ...). - $sort : bool|null = null
-
Whether to sort the keys alphabetically.
Tags
Return values
string —The formatted AQL expression.
count()
Return the number of attribute keys of a document (an alias of {@see length()} / `LENGTH()`).
count(string $document) : string
Wraps the ArangoDB AQL function COUNT(document).
Example AQL usage:
COUNT({a: 1, b: 2}) // returns 2
Parameters
- $document : string
-
The document variable or expression.
Tags
Return values
string —The formatted AQL expression.
entries()
Return the attributes of a document as an array of key/value pairs.
entries(string $document) : string
Wraps the ArangoDB AQL function ENTRIES(document).
Example AQL usage:
ENTRIES({a: 1, b: 2}) // returns [["a", 1], ["b", 2]]
Parameters
- $document : string
-
The document variable or expression.
Tags
Return values
string —The formatted AQL expression.
has()
Returns an AQL expression to test whether an attribute exists in a document.
has(string $document, string $attributeName) : string
This helper wraps the ArangoDB AQL function HAS(document, attributeName) which
returns true if the document has an attribute named attributeName, even if its
value is falsy (null, 0, false, or empty string).
Example AQL usage:
HAS(doc, "name") // returns true if doc has a "name" attribute
HAS(doc, "email") // returns true if doc has an "email" attribute
HAS(doc, "nonExistent") // returns false if attribute doesn't exist
Parameters
- $document : string
-
The document variable or expression to test.
- $attributeName : string
-
The attribute key to test for existence.
Tags
Return values
string —The formatted AQL expression.
isSameCollection()
Test whether a document identifier belongs to a given collection.
isSameCollection(string $collectionName, string $documentIdentifier) : string
Wraps the ArangoDB AQL function IS_SAME_COLLECTION(collectionName, documentIdentifier).
The collection name is emitted as a quoted string literal (json_encode); the document
identifier stays a raw expression (typically doc._id).
Example AQL usage:
IS_SAME_COLLECTION("products", "products/123") // returns true
IS_SAME_COLLECTION("products", doc._id) // true if doc lives in products
Parameters
- $collectionName : string
-
The collection name (emitted as a quoted string literal).
- $documentIdentifier : string
-
A document handle /
_idexpression or string literal.
Tags
Return values
string —The formatted AQL expression.
keep()
Keep only the given top-level attributes of a document.
keep(string $document, string ...$attributes) : string
Wraps the ArangoDB AQL function KEEP(document, attributeName1, … attributeNameN).
The attribute names are emitted as quoted string literals (json_encode), so AQL
receives a valid call; the document stays a raw expression.
Example AQL usage:
KEEP(doc, "name", "age") // a copy of doc with only its name and age attributes
Parameters
- $document : string
-
The document variable or expression.
- $attributes : string
-
The attribute names to keep.
Tags
Return values
string —The formatted AQL expression.
keepRecursive()
Keep only the given attributes of a document, recursing into sub-documents.
keepRecursive(string $document, string ...$attributes) : string
Wraps the ArangoDB AQL function KEEP_RECURSIVE(document, attributeName1, … attributeNameN).
The attribute names are emitted as quoted string literals (json_encode); the document
stays a raw expression.
Example AQL usage:
KEEP_RECURSIVE(doc, "name", "meta") // keeps name/meta at every nesting level
Parameters
- $document : string
-
The document variable or expression.
- $attributes : string
-
The attribute names to keep at every level.
Tags
Return values
string —The formatted AQL expression.
keys()
Return the attribute keys of a document (an alias of {@see attributes()} / `ATTRIBUTES()`).
keys(string $document[, bool|null $removeSystemAttrs = null ][, bool|null $sort = null ]) : string
Wraps the ArangoDB AQL function KEYS(document, removeSystemAttrs, sort).
Example AQL usage:
KEYS({b: 2, a: 1}) // returns ["b", "a"]
KEYS({b: 2, a: 1}, false, true) // returns ["a", "b"] (sorted)
Parameters
- $document : string
-
The document variable or expression.
- $removeSystemAttrs : bool|null = null
-
Whether to omit system attributes (
_id,_key,_rev, ...). - $sort : bool|null = null
-
Whether to sort the keys alphabetically.
Tags
Return values
string —The formatted AQL expression.
length()
Return the number of attribute keys of a document.
length(string $document) : string
Wraps the ArangoDB AQL function LENGTH(document) (also aliased as COUNT()).
Example AQL usage:
LENGTH({a: 1, b: 2}) // returns 2
Parameters
- $document : string
-
The document variable or expression.
Tags
Return values
string —The formatted AQL expression.
matches()
Test whether a document matches one of the given example documents.
matches(string $document, string|array<string|int, mixed> $examples[, bool|null $returnIndex = null ]) : string
Wraps the ArangoDB AQL function MATCHES(document, examples, returnIndex). The
examples argument is emitted as a JSON literal when given as a PHP array; a string
is passed through as a raw AQL expression. With $returnIndex = true, the function
returns the (zero-based) index of the first matching example instead of a boolean.
Example AQL usage:
MATCHES(doc, {age: 30}) // true if doc.age == 30
MATCHES(doc, [{age: 30}, {age: 40}], true) // index of the first matching example, or -1
Parameters
- $document : string
-
The document variable or expression to test.
- $examples : string|array<string|int, mixed>
-
A single example or a list of examples (array literal or AQL expression).
- $returnIndex : bool|null = null
-
Whether to return the matching example index instead of a boolean.
Tags
Return values
string —The formatted AQL expression.
merge()
Merge multiple documents into a single document.
merge(string|array<string|int, mixed>|null $documents) : string
This helper wraps the ArangoDB AQL function MERGE(document1, document2, ... documentN)
which merges multiple documents into a single document. Later documents override
attributes from earlier documents if they have the same key.
Example AQL usage:
MERGE(doc1, doc2) // merges doc1 and doc2
MERGE(doc1, doc2, doc3) // merges three documents
MERGE({a: 1}, {b: 2}) // returns {a: 1, b: 2}
MERGE({a: 1}, {a: 2}) // returns {a: 2} (later overrides)
Parameters
- $documents : string|array<string|int, mixed>|null
-
Multiple documents to merge (at least 2 required).
Tags
Return values
string —The formatted AQL expression.
mergeRecursive()
Recursively merge multiple documents into a single document.
mergeRecursive(string|array<string|int, mixed>|null $documents) : string
Wraps the ArangoDB AQL function MERGE_RECURSIVE(document1, … documentN). Unlike
merge(), sub-documents with the same key are merged recursively rather than
replaced wholesale.
Example AQL usage:
MERGE_RECURSIVE({a: {b: 1}}, {a: {c: 2}}) // returns {a: {b: 1, c: 2}}
Parameters
- $documents : string|array<string|int, mixed>|null
-
Multiple documents to merge (at least 2 required).
Tags
Return values
string —The formatted AQL expression.
parseCollection()
Return the collection name part of a document identifier.
parseCollection(string $documentIdentifier) : string
Wraps the ArangoDB AQL function PARSE_COLLECTION(documentIdentifier).
Example AQL usage:
PARSE_COLLECTION("products/123") // returns "products"
PARSE_COLLECTION(doc._id) // collection of the current document
Parameters
- $documentIdentifier : string
-
A document handle /
_idexpression or string literal.
Tags
Return values
string —The formatted AQL expression.
parseIdentifier()
Return the collection name and key of a document identifier as an object.
parseIdentifier(string $documentIdentifier) : string
Wraps the ArangoDB AQL function PARSE_IDENTIFIER(documentIdentifier), which
returns { collection, key }.
Example AQL usage:
PARSE_IDENTIFIER("products/123") // returns {collection: "products", key: "123"}
PARSE_IDENTIFIER(doc._id) // parts of the current document handle
Parameters
- $documentIdentifier : string
-
A document handle /
_idexpression or string literal.
Tags
Return values
string —The formatted AQL expression.
parseKey()
Return the key part of a document identifier.
parseKey(string $documentIdentifier) : string
Wraps the ArangoDB AQL function PARSE_KEY(documentIdentifier).
Example AQL usage:
PARSE_KEY("products/123") // returns "123"
PARSE_KEY(doc._id) // key of the current document
Parameters
- $documentIdentifier : string
-
A document handle /
_idexpression or string literal.
Tags
Return values
string —The formatted AQL expression.
translate()
Look up the specified value in a lookup document and return the mapped value.
translate(mixed $value, mixed $lookupDocument[, mixed $defaultValue = null ]) : string
This helper wraps the ArangoDB AQL function TRANSLATE(value, lookupDocument, defaultValue)
which performs a lookup operation. If the value is a key in the lookup document,
it returns the corresponding value. If not found, it returns the default value
(if specified) or the original value unchanged.
Example AQL usage:
TRANSLATE("draft", {"draft": "D", "published": "P"}) // returns "D"
TRANSLATE("unknown", {"draft": "D", "published": "P"}) // returns "unknown"
TRANSLATE("unknown", {"draft": "D", "published": "P"}, "X") // returns "X"
Parameters
- $value : mixed
-
The value to look up in the lookup document.
- $lookupDocument : mixed
-
The document containing key-value mappings.
- $defaultValue : mixed = null
-
Optional default value to return if key is not found.
Tags
Return values
string —The formatted AQL expression.
unsetAttributes()
Remove the given top-level attributes from a document.
unsetAttributes(string $document, string ...$attributes) : string
Wraps the ArangoDB AQL function UNSET(document, attributeName1, … attributeNameN).
The attribute names are emitted as quoted string literals (json_encode); the document
stays a raw expression.
Named
unsetAttributes()rather thanunset()becauseunsetis a reserved PHP keyword.
Example AQL usage:
UNSET(doc, "_id", "_rev") // a copy of doc without its _id and _rev attributes
Parameters
- $document : string
-
The document variable or expression.
- $attributes : string
-
The attribute names to remove.
Tags
Return values
string —The formatted AQL expression.
unsetRecursive()
Remove the given attributes from a document, recursing into sub-documents.
unsetRecursive(string $document, string ...$attributes) : string
Wraps the ArangoDB AQL function UNSET_RECURSIVE(document, attributeName1, … attributeNameN).
The attribute names are emitted as quoted string literals (json_encode); the document
stays a raw expression.
Example AQL usage:
UNSET_RECURSIVE(doc, "_id", "_rev") // strips _id/_rev at every nesting level
Parameters
- $document : string
-
The document variable or expression.
- $attributes : string
-
The attribute names to remove at every level.
Tags
Return values
string —The formatted AQL expression.
value()
Extract a value from a document at the specified path.
value(string $document, array<string|int, mixed> $path) : string
This helper wraps the ArangoDB AQL function VALUE(document, path) which extracts
a value from a document using a path array. The path can contain strings (object keys)
and integers (array indices) to navigate through nested structures.
Example AQL usage:
VALUE(doc, ["author", "name"]) // extracts doc.author.name
VALUE(doc, ["tags", 0]) // extracts first element of doc.tags array
VALUE(doc, ["metadata", "version"]) // extracts doc.metadata.version
Parameters
- $document : string
-
The document variable or expression to extract value from.
- $path : array<string|int, mixed>
-
An array of strings and numbers describing the attribute path. Use strings for object keys and integers for array indices.
Tags
Return values
string —The formatted AQL expression.
values()
Return the attribute values of a document.
values(string $document[, bool|null $removeSystemAttrs = null ]) : string
Wraps the ArangoDB AQL function VALUES(document, removeSystemAttrs).
Example AQL usage:
VALUES({a: 1, b: 2}) // returns [1, 2]
VALUES({a: 1, _key: "x"}, true) // returns [1]
Parameters
- $document : string
-
The document variable or expression.
- $removeSystemAttrs : bool|null = null
-
Whether to omit system attributes (
_id,_key,_rev, ...).
Tags
Return values
string —The formatted AQL expression.
zip()
Build a document from an array of attribute keys and an array of values.
zip(string|array<string|int, mixed> $keys, string|array<string|int, mixed> $values) : string
Wraps the ArangoDB AQL function ZIP(keys, values). PHP arrays are emitted as JSON
array literals (json_encode); strings are passed through as raw AQL expressions
(e.g. doc.keys).
Example AQL usage:
ZIP(["a", "b"], [1, 2]) // returns {a: 1, b: 2}
Parameters
- $keys : string|array<string|int, mixed>
-
The attribute keys (array literal or AQL expression).
- $values : string|array<string|int, mixed>
-
The values, in the same order (array literal or AQL expression).
Tags
Return values
string —The formatted AQL expression.