简体   繁体   中英

Get neo4j result

I'm using neo4j jdbc driver to access a local service and make the following query to find what I need:

"MATCH (u:User)-->(d:Deck)-[p:Played]->(g:Game)" +
"WHERE id(g) = ?" +
"RETURN {r {user :u, deck :d, played:p, game:g}}"

I cast it as a map and can find the parts and, right there in my face, I can see the stuff I need. How do I get it? (the {comment= ...} etc)

在此处输入图片说明

I do know how to get it by

RETURN p.comment, p.place ... etc 

But I fear this will soon get out of hand. If I can just get at least that json string I would be happy.

There is a built-in Cypher function PROPERTIES() , outlined here , that will convert anything that has properties (nodes, relationships, even pre-existing Maps) to a Map of the properties with no other data. The language drivers have built-in tools to hydrate Nodes and Relationships so that property access is simple, but if you require a Map and only a Map to be returned, just use RETURN PROPERTIES(p) and you'll get it.

Reading between the lines, it looks like you are trying to get all the properties of specific nodes and properties, without any extraneous metadata.

After installing the APOC plugin, you can use the apoc.map.fromPairs procedure to generate a map with all the properties of a node or relationship.

For example, to get all the properties of every User node:

MATCH (u:User)
CALL apoc.map.fromPairs([k IN KEYS(u) | [k, u[k]]]) YIELD value AS props
RETURN props;
  • [k IN KEYS(u) | [k, u[k]]] [k IN KEYS(u) | [k, u[k]]] generates a collection of key/value collections.
  • The apoc.map.fromPairs() procedure takes a collection of key/value collections, and converts it into a map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM