How to create a completely new object from a query

Neo4j server community 4.3.3 - Linux Ubuntu 20.04

Hi,

I wasn't able to answer the following question:

I have two nodes: a User and a Recipe, both have an uuid and a name.

I want to execute the following query:

MATCH (user:User {uuid: $UserUuid}
MATCH (recipe:Recipe {uuid: $recipeUuid}

OPTIONAL  MATCH (recipe)<-[evaluation:IS_EVALUATING]-(user)

then I want to return just one new object, called newEvaluation as in the following pseudocode:

return (user.uuid, user.name, recipe.uuid, recipe.name, evaluation.properties) as newEvaluation.

if there is no relationship, the evaluation.properties should be null.

I experimenting a lot, but I always got four text columns and a node, while I need the node to be splattered and everything should appear as a new node.

Any suggestion will be appreciated.

Thanks

You can return a map/dict/object by creating a literal map

MATCH (user:User {uuid: $UserUuid}
MATCH (recipe:Recipe {uuid: $recipeUuid}

OPTIONAL  MATCH (recipe)<-[evaluation:IS_EVALUATING]-(user)

RETURN { userId: user.uuid, userName: user.name, recipeId: recipe.uuid, recipeTitle: recipe.name, evaluation: evaluation.properties } as result
1 Like