arangodb/python-arango

What is the fastest way to get all documents of a collection?

Closed this issue · 2 comments

I have a problem. I want to get all documents of a collection with ~ 1 mio documents inside. I asked myself what is the fastest way to get all documents inside a collection. Is it with cursor or with .all? And are there any recommendation for the batch_size? I would really appreciate a answer, thank you in advance.

cursor

from arango import ArangoClient

# Initialize the ArangoDB client.
client = ArangoClient()

# Connect to database as  user.
db = client.db(<db>, username=<username>, password=<password>)

cursor = db.aql.execute('FOR doc IN <Collection> RETURN doc', stream=True, ttl=3600, batch_size=<batchSize>)
collection =  [doc for doc in cursor]

.all - with custom HTTP Client

from arango import ArangoClient
from arango.http import HTTPClient

class MyCustomHTTPClient(HTTPClient):
    REQUEST_TIMEOUT = 1000

# Initialize the ArangoDB client.
client = ArangoClient(
    http_client=MyCustomHTTPClient())

# Connect to database as  user.
db = client.db(<db>, username=<username>, password=<password>)

students = db.collection('students')
collection = students.all()

Hi @rosenberg12,

I recommend you use the first. If I remember correctly .all basicall calls the cursor method, and may be deprecated in the future. As for the batch size, I'd guess the bigger than better as long as you can hold the results safely in memory.

Closing this due to inactivity. Feel free to re-open if you have any other questions.