Say I have a graph that has vertices of labels 'Company' 'CarModel' and 'Parts' where a company has many car models and Car models have many parts. How can I query the Database to return to me all the properties of the Company with 'CarModels' as property that would be an array of the CarModel vertices then again return all the properties of CarModel with Parts as an additional property that has all the properties of Parts?
Asked
Active
Viewed 129 times
0
-
For questions that need a Gremlin query as the answer, it is extremely helpful if you can provide a sample graph so that answers can be tested. An example of such a sample graph can be seen here: https://stackoverflow.com/questions/70366528/using-a-back-step-to-get-two-connected-vertexes/70367339#70367339 – Kelvin Lawrence Dec 20 '21 at 15:24
1 Answers
1
You can use project
step if you want to structure your answer and collect the required data from the graph for each key:
g.V().hasLabel('Company').
has('name', <Company Name>).
project('CompanyData', 'CarModels').
by(valueMap()).
by(out().
project('CarModelData', 'Parts').
by(valueMap()).
by(out().valueMap().fold()).fold())
example: https://gremlify.com/md1j1rzgigt

noam621
- 2,766
- 1
- 16
- 26