cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

List of nodes in nodejs

i am using the following query-
match p = (a:label1)-->(b:label2) return nodes(p)

its returning me results like this-
[{a1,b1},{a1,b2}, {a2,b3}, {a2,b4}]

but i need result in this form-
[{a1},{a2},{b1},{b2},{b3},{b4}]

i have rather very long path and i just need a list of nodes collected on the way(with properties) to display as search result. the labels are different.

1 ACCEPTED SOLUTION

@ag.nishu,

Please try
MATCH p=(n:CO)-[:HAS_ITEM]->(m:COI) RETURN collect(distinct n), collect(distinct m )

View solution in original post

5 REPLIES 5

MuddyBootsCode
Graph Steward

You might try:

MATCH p = (a:label1)-[]->(b:label2)
RETURN a, b

it gives me same result..

MATCH p=(n:CO)-[:HAS_ITEM]->(m:COI) RETURN n,m

[
{
"keys": [
"n",
"m"
],
"length": 2,
"_fields": [
{
"identity": {
"low": 8,
"high": 0
},
"labels": [
"CO"
],
"properties": {
"type": "WIRES",
"eref": "E98722"
}
},
{
"identity": {
"low": 12,
"high": 0
},
"labels": [
"COI"
],
"properties": {
"type": "Provide",
"product": "Connection",
"status": "In-Progress"
}
}
],
"_fieldLookup": {
"n": 0,
"m": 1
}
},
{
"keys": [
"n",
"m"
],
"length": 2,
"_fields": [
{
"identity": {
"low": 8,
"high": 0
},
"labels": [
"CO"
],
"properties": {
"type": "WIRES ",
"eref": "E98722"
}
},
{
"identity": {
"low": 14,
"high": 0
},
"labels": [
"COI"
],
"properties": {
"type": "Cease",
"product": "CISCO",
"status": "In-Progress"
}
}
],
"_fieldLookup": {
"n": 0,
"m": 1
}
},
{
"keys": [
"n",
"m"
],
"length": 2,
"_fields": [
{
"identity": {
"low": 10,
"high": 0
},
"labels": [
"CO"
],
"properties": {
"type": "CSP",
"eref": "E08779"
}
},
{
"identity": {
"low": 11,
"high": 0
},
"labels": [
"COI"
],
"properties": {
"type": "Provide",
"product": "Connection"
}
}
],
"_fieldLookup": {
"n": 0,
"m": 1
}
},
{
"keys": [
"n",
"m"
],
"length": 2,
"_fields": [
{
"identity": {
"low": 10,
"high": 0
},
"labels": [
"CO"
],
"properties": {
"type": "CSP",
"eref": "E08779"
}
},
{
"identity": {
"low": 13,
"high": 0
},
"labels": [
"COI"
],
"properties": {
"type": "Provide",
"product": "IP Clear Access",
"status": "In-Progress"
}
}
],
"_fieldLookup": {
"n": 0,
"m": 1
}
}
]

my requirement is to get CO and COI as separate nodes in the result.

@ag.nishu,

Please try
MATCH p=(n:CO)-[:HAS_ITEM]->(m:COI) RETURN collect(distinct n), collect(distinct m )

thats so cool, thanks Vivek