I have a data schema where users can review products. user
and product
are vertices, and reviews
is a MANY2MANY relation between users
and products
. reviews
has edge properties such as title and body.
I want to write a query to get all reviews for a product, as well as the users that wrote the review. I can get the reviews using the following, but I don't know how to add all the user properties.
g.({product}).inE("reviews").values()
How can I get user information per review as well?
You could do something like this:
l = g.V(pvid). // start with a product vertex id
inE("reviews").as("r"). // label the review edges
outV().as("u"). // label the users
select("r", "u").by(valueMap()). // properties map
toList() // iterate traversal into a list
This will return a list of maps. Each map will have 2 keys, r
and u
, corresponding to the select("r", "u")
step. Then the value of the r
in the map are the properties for the review. Similarly the value of the u
in the map are the properties for the user.
Related documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With