Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-27-2022 08:06 AM
I want to display all the nodes and its properties in json format using NodeJs
But with this code it is showing error
Solved! Go to Solution.
08-28-2022 01:11 PM
You will need to change your query to get the related nodes. The following query matches on every node, then gets related nodes if the exists. It returns the data in a map, with keys 'node' and 'relatedNodes'. The node's value is a map of the node's properties and the relatedNodes is a list of property maps for each related node.
match(n)
optional match (n)--(m)
with n as node, collect(properties(m)) as relatedNodes
return {node: node, relatedNodes: relatedNodes} as json
Replace your query with the above cypher and use record.get("json"). The result should be a map that you can extract its key/value pairs using dot notation.
If you don't want the json output, but the items individually, then use the following query and use record.get("node") to get the node properties and record.get("relatedNodes") to get a list of the related nodes' properties.
match(n)
optional match (n)--(m)
return n as node, collect(properties(m)) as relatedNodes
If this doesn't give you the format you want, please describe it so we can format the data appropriately.
08-27-2022 01:29 PM
Try removing the semicolon. If that doesn’t help, can you provide the error?
08-28-2022 06:41 AM
After removing semicolon from cypher it still shows error
08-28-2022 11:26 AM
It looks like it does not understand the following snippet:
record._fields[0].end.properties
I don't use the js driver, but from the documentation I could not find a reference to '_fields' property/method on the 'record' object. There is a 'keys' member that returns an array of the Field keys in the order the fields appear in the record. Where did you get this syntax?
Anyways, you should only have one field resulting from your query, since your return statement only has node 'N'. You can get this from the record using 'record.get("N")'. After getting the node, you should be able to get its labels from 'node.labels' and properties from 'node.properties'.
08-28-2022 11:48 AM
How should 'node.labels' and 'node.properties' should be added?
And after making changes to 'record.get("N")' it is only showing nodes and their data . In JSON format it is not showing relations between nodes in form of array like structure
I want to display the data in similar format like in the above link
08-28-2022 01:11 PM
You will need to change your query to get the related nodes. The following query matches on every node, then gets related nodes if the exists. It returns the data in a map, with keys 'node' and 'relatedNodes'. The node's value is a map of the node's properties and the relatedNodes is a list of property maps for each related node.
match(n)
optional match (n)--(m)
with n as node, collect(properties(m)) as relatedNodes
return {node: node, relatedNodes: relatedNodes} as json
Replace your query with the above cypher and use record.get("json"). The result should be a map that you can extract its key/value pairs using dot notation.
If you don't want the json output, but the items individually, then use the following query and use record.get("node") to get the node properties and record.get("relatedNodes") to get a list of the related nodes' properties.
match(n)
optional match (n)--(m)
return n as node, collect(properties(m)) as relatedNodes
If this doesn't give you the format you want, please describe it so we can format the data appropriately.
All the sessions of the conference are now available online