-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharango_get_items.py
More file actions
26 lines (21 loc) · 827 Bytes
/
Copy patharango_get_items.py
File metadata and controls
26 lines (21 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from arango import ArangoClient
from arango.collection import StandardCollection
import arango as aq
from operator import itemgetter
def get_items(db_name, collection_name, name):
""" Connect to arangoDB to get documents from a collection
Args:
db_name: database name
collection_name: collection name
name: key for requested item from collection
Returns:
(list of dictionaries) - keys and items
"""
client = ArangoClient(hosts='http://localhost:8529')
db = client.db(db_name, username= 'root', password='admin')
query = 'For doc in '+collection_name+' return doc'
aql = db.aql
cursor = aql.execute(query)
outcome = [res for res in cursor]
outcome = [{'_key': item.get('_key'), name:item.get(name)} for item in outcome]
return outcome