key value - Iterative querying the ArangoDB using AQL -


i have stored json data in arangodb collection in following format.

{    "data": {     "1":   [ {"db_name": "dsp"}, {"rel": "2"} ],      "2":   [ {"rel_name": "datasource"}, {"tuple": "201"}, {"tuple": "202"}, {"tuple": "203"} ],     "201": [ {"src_id": "pos201510070"}, {"src_name": "postgres"}, {"password": "root"}, {"host": "localhost"}, {"created_date": "20151007"}, {"user_name": "postgres"}, {"src_type": "structured"}, {"db_name": "postgres"}, {"port": "none"} ],     "202": [ {"src_id": "pos201510060"}, {"src_name": "postgres"},{"password": "root"}, {"host": "localhost"}, {"created_date": "20151006"}, {"user_name": "postgres"}, {"src_type": "structured"}, {"db_name": "dsp"}, {"port": "5432"} ],     "203": [ {"src_id": "pos201510060"}, {"src_name": "postgres"}, {"password": "root"}, {"host": "localhost"}, {"created_date": "20151006"}, {"user_name": "postgres"},{"src_type": "structured"},{"db_name": "maindb"},{"port": "5432"} ]   } } 

i new arangodb. have no idea storing , querying data arangodb. in data there no predefined key, , data populated time. data semi-structured data not have fixed number of attributes, , little bit complex due iterative list structure.

first, can suggest me best way storing above format in arangodb.

second, want query data in following manner: specifying key (not known in advance, specifying @ runtime), or specify combinations of key , value pair, e.g., key1 == value1, or combination using , or or logical operators key1 == value1 , key2 == value2 or key3== value3.

so, how can iterate on above data?

if want store data in structure this, without predefined attribute names, can still iterate on data converting normalized structure on-the-fly.

the following aql query creates flat list of key/value pairs each document:

for doc in collection    let attributes = attributes(doc.data)    attribute in attributes      arrayitem in doc.data[attribute]        let key = attributes(arrayitem)[0]        let value = arrayitem[key]        return { _key: doc._key key: key, value: value } 

the result of query this:

[    {      "_key" : "864582648369",      "key" : "password",      "value" : "root"    },    {      "_key" : "864582648369",      "key" : "db_name",      "value" : "postgres"    },    {      "_key" : "864582648369",      "key" : "port",      "value" : "none"    },    ... ] 

now can apply filtering adding filter conditions of choice:

for doc in collection    let attributes = attributes(doc.data)    attribute in attributes      arrayitem in doc.data[attribute]        let key = attributes(arrayitem)[0]        let value = arrayitem[key]        filter key == 'password' || key == 'port' || (key == 'db_name' && value == 'postgres')        return { _key: doc._key, key: key, value: value } 

note when data structure changes (more/less levels of nesting), above won't work anymore. query assumes documents structure presented in question.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -