I would like to be able to fetch my categories in my graph database in a way that the children of the categories will be inside children
property.
I know this is possible with project step, but how do I use it with tree step?
This is the array structure that I want to achieve:
[
{
'name' : 'shoes',
'children': [
{
'name' : 'nike',
'children' : [
{
'name' : 'jordan 1',
'children' : []
},
{
'name' : 'air force 1',
'children' : []
},
],
},
{
'name' : 'adidas',
'children': [
{
'name' : 'nike',
'children' : [
{
'name' : 'yeezy',
'children' : []
},
{
'name' : 'stan smith',
'children' : []
},
],
},
],
},
],
},
]
Please see image below to see the graph database.
Use the below code to seed your graph database from the image above.
g
.addV('category')
.property('name', 'shoes')
.as('shoes')
.addE('has')
.to(
addV('category')
.property('name', 'nike')
.as('nike')
.addE('has')
.to(
addV('category')
.property('name', 'air force 1')
)
.select('nike')
.addE('has')
.to(
addV('category')
.property('name', 'jordan 1')
)
.select('nike')
)
.select('shoes')
.addE('has')
.to(
addV('category')
.property('name', 'adidas')
.as('adidas')
.addE('has')
.to(
addV('category')
.property('name', 'yeezy')
)
.select('adidas')
.addE('has')
.to(
addV('category')
.property('name', 'stan smith')
)
.select('adidas')
)