mirror of https://gitee.com/bigwinds/arangodb
22 lines
621 B
Plaintext
22 lines
621 B
Plaintext
!CHAPTER Counting
|
|
|
|
!SECTION Amount of documents in a collection
|
|
|
|
To return the count of documents that currently exist in a collection,
|
|
you can call the [LENGTH() function](../Aql/ArrayFunctions.md#length):
|
|
|
|
```
|
|
RETURN LENGTH(collection)
|
|
```
|
|
|
|
This type of call is optimized since 2.8 (no unnecessary intermediate result
|
|
is built up in memory) and it is therefore the prefered way to determine the count.
|
|
In earlier versions with `COLLECT ... WITH COUNT INTO` available (since 2.4),
|
|
you may use the following code for better performance instead:
|
|
|
|
```
|
|
FOR doc IN collection
|
|
COLLECT WITH COUNT INTO length
|
|
RETURN length
|
|
```
|