Neo4j documents structure for array typess -


i trying model trading network accounts can trade multiple items in single trade. i'd use neo4j able identify , visualize account behavior, , movement of specific items

our mongodb documents this

{     _id: 1233 // doc id     date: isodate("2015-05-01t01:00:00"),     trade_id: 21312      account: 'joe'     to_account: 'tim'      items:     [        { name: 'oil',count: '5' },        { name: 'sunscreen', count: 1}     ]  }, {     _id: 1234 // doc id     date: isodate("2015-05-01t01:00:00"),     trade_id: 21312      account: 'tim'     to_account: 'joe'      items:     [        { name: 'peas',count: '100' },     ]  } 

what best structure within neo4j database? struggling how best deal nature of arrays i'd able ask db, list me accounts have traded 'sunscreen' 'peas'.

thanks.

an array set of records - in neo4j correspond nodes same label.

a candidate design set of "trade" , "item" nodes so:

create (trade:trade {id: 1233,                       date: "2015-05-01t01:00:00",                       trade_id: 21312,                      account: 'joe',                      to_account: 'tim'})  create (itm1:item {name: 'oil',       count: 5}) create (itm2:item {name: 'sunscreen', count: 1})  create (trade)-[:item]->(itm1) create (trade)-[:item]->(itm2) 

the ":trade" nodes enclosing values, , ":item" nodes correspond "item" array elements.

to values - match() relationship between ":trade" , ":item" nodes using :item relationship - so:

match (trade:trade)-[ritm:item]->(itm:item) return trade, ritm, itm 

update version splits account info own set of labeled nodes , stores item quantities in own set of labeled nodes. follows more "rdb" way of looking @ things. assumes there's item-line specific information beyond qty needs tracked.

// ensure accounts exist  merge (fromacct:account {account: 'joe'}) merge (toacct:account   {account: 'tim'})  // ensure items exist  merge (item1:item {name: 'oil}) merge (item2:item {name: 'sunscreen'})  // create trade transaction  create (trade:trade {id: 1233,                      date: "2015-05-01t01:00:00",                       trade_id: 21312                      })  // create item line records  create (itemline1:itemline {count: 5}) create (itemline2:itemline {count: 2})  // link trade item lines  create (trade)-[:itemline]->(itemline1) create (trade)-[:itemline]->(itemline2)  // link item lines items  create (itemline1)-[:item]->(item1) create (itemline2)-[:item]->(item2)  // link trade items  create (trade)-[:item]->(item1) create (trade)-[:item]->(item2) 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo