Skip to content

Commit 4ae4be9

Browse files
Simran-BCircleCICircleCI Job
authored
Add PARSE_KEY() and PARSE_COLLECTION() functions (#386)
* Add PARSE_KEY() and PARSE_COLLECTION() functions * [skip ci] Automatic commit of generated files from CircleCI --------- Co-authored-by: CircleCI <[email protected]> Co-authored-by: CircleCI Job <[email protected]>
1 parent efa2848 commit 4ae4be9

File tree

4 files changed

+109
-16
lines changed

4 files changed

+109
-16
lines changed

site/content/3.12/aql/functions/document-object.md

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -632,24 +632,56 @@ RETURN MERGE_RECURSIVE(
632632
)
633633
```
634634

635-
## PARSE_IDENTIFIER()
635+
## PARSE_COLLECTION()
636636

637-
`PARSE_IDENTIFIER(documentIdentifier) → parts`
637+
`PARSE_COLLECTION(documentIdentifier) → collectionName`
638638

639639
Parse a [document ID](../../concepts/data-structure/documents/_index.md#document-identifiers) and
640-
return its individual parts as separate attributes.
640+
return the collection name.
641+
642+
- **documentIdentifier** (string\|object): a document identifier string (e.g. `_users/1234`)
643+
or a regular document from a collection. Passing either a non-string or a non-document
644+
or a document without an `_id` attribute results in an error.
645+
- returns **collectionName** (string): the name of the collection
646+
647+
**Examples**
648+
649+
Parse a document identifier string and extract the collection name:
650+
651+
```aql
652+
---
653+
name: aqlParseCollection_1
654+
description: ''
655+
---
656+
RETURN PARSE_COLLECTION("_users/my-user")
657+
```
658+
659+
Parse the `_id` attribute of a document to extract the collection name:
660+
661+
```aql
662+
---
663+
name: aqlParseCollection_2
664+
description: ''
665+
---
666+
RETURN PARSE_COLLECTION( { "_id": "mycollection/mykey", "value": "some value" } )
667+
```
668+
669+
## PARSE_IDENTIFIER()
670+
671+
`PARSE_IDENTIFIER(documentIdentifier) → parts`
641672

642-
This function can be used to easily determine the
643-
[collection name](../../concepts/data-structure/collections.md#collection-names) and key of a given document.
673+
Parse a [document ID](../../concepts/data-structure/documents/_index.md#document-identifiers)
674+
and separately return the collection name and the document key.
644675

645676
- **documentIdentifier** (string\|object): a document identifier string (e.g. `_users/1234`)
646677
or a regular document from a collection. Passing either a non-string or a non-document
647-
or a document without an `_id` attribute will result in an error.
648-
- returns **parts** (object): an object with the attributes *collection* and *key*
678+
or a document without an `_id` attribute results in an error.
679+
- returns **parts** (object): an object with the attributes `collection` and `key`
649680

650681
**Examples**
651682

652-
Parse a document identifier string:
683+
Parse a document identifier string and extract both the collection name and the
684+
document key:
653685

654686
```aql
655687
---
@@ -659,7 +691,8 @@ description: ''
659691
RETURN PARSE_IDENTIFIER("_users/my-user")
660692
```
661693

662-
Parse the document identifier string of a document (`_id` attribute):
694+
Parse the `_id` attribute of a document to extract both the collection name and
695+
the document key:
663696

664697
```aql
665698
---
@@ -669,6 +702,40 @@ description: ''
669702
RETURN PARSE_IDENTIFIER( { "_id": "mycollection/mykey", "value": "some value" } )
670703
```
671704

705+
## PARSE_KEY()
706+
707+
`PARSE_KEY(documentIdentifier) → key`
708+
709+
Parse a [document ID](../../concepts/data-structure/documents/_index.md#document-identifiers) and
710+
return the document key.
711+
712+
- **documentIdentifier** (string\|object): a document identifier string (e.g. `_users/1234`)
713+
or a regular document from a collection. Passing either a non-string or a non-document
714+
or a document without an `_id` attribute results in an error.
715+
- returns **key** (string): the document key
716+
717+
**Examples**
718+
719+
Parse a document identifier string and extract the document key:
720+
721+
```aql
722+
---
723+
name: aqlParseKey_1
724+
description: ''
725+
---
726+
RETURN PARSE_KEY("_users/my-user")
727+
```
728+
729+
Parse the `_id` attribute of a document to extract the document key:
730+
731+
```aql
732+
---
733+
name: aqlParseKey_2
734+
description: ''
735+
---
736+
RETURN PARSE_KEY( { "_id": "mycollection/mykey", "value": "some value" } )
737+
```
738+
672739
## TRANSLATE()
673740

674741
`TRANSLATE(value, lookupDocument, defaultValue) → mappedValue`

site/content/3.12/aql/functions/string.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,9 @@ Split the given string `value` into a list of strings, using the `separator`.
14291429

14301430
To split a document identifier (`_id`) into the collection name and document key
14311431
(`_key`), you should use the more optimized
1432-
[`PARSE_IDENTIFIER()` function](document-object.md#parse_identifier).
1432+
[`PARSE_IDENTIFIER()` function](document-object.md#parse_identifier), respectively
1433+
[`PARSE_COLLECTION()`](document-object.md#parse_collection) or
1434+
[`PARSE_KEY()`](document-object.md#parse_key) to only extract the name or key.
14331435

14341436
- **value** (string): a string
14351437
- **separator** (string): either a string or a list of strings. If `separator` is

site/content/3.12/release-notes/version-3.12/whats-new-in-3-12.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ UPDATE { logins: OLD.logins + 1 } IN users
174174

175175
Read more about [`UPSERT` operations](../../aql/high-level-operations/upsert.md) in AQL.
176176

177+
### Added AQL functions
178+
179+
The new `PARSE_COLLECTION()` and `PARSE_KEY()` let you more extract the
180+
collection name respectively the document key from a document identifier with
181+
less overhead.
182+
183+
See [Document and object functions in AQL](../../aql/functions/document-object.md#parse_collection).
184+
177185
## Indexing
178186

179187
### Stored values can contain the `_id` attribute

0 commit comments

Comments
 (0)