Neo4j loop for all children
In Neo4j I got the following nodes:
As you can see, they are siblings connected by relationships as NEXT or NEXT_SIBLING; moreover, the first and last child are connected to the father by FIRST_CHILD_OF and LAST_CHILD_OF.
I simply want to find a way to cycle them in order to create a single string which is "A B C D".
Is there a Cypher query capable of this?
neo4j cypher
add a comment |
In Neo4j I got the following nodes:
As you can see, they are siblings connected by relationships as NEXT or NEXT_SIBLING; moreover, the first and last child are connected to the father by FIRST_CHILD_OF and LAST_CHILD_OF.
I simply want to find a way to cycle them in order to create a single string which is "A B C D".
Is there a Cypher query capable of this?
neo4j cypher
add a comment |
In Neo4j I got the following nodes:
As you can see, they are siblings connected by relationships as NEXT or NEXT_SIBLING; moreover, the first and last child are connected to the father by FIRST_CHILD_OF and LAST_CHILD_OF.
I simply want to find a way to cycle them in order to create a single string which is "A B C D".
Is there a Cypher query capable of this?
neo4j cypher
In Neo4j I got the following nodes:
As you can see, they are siblings connected by relationships as NEXT or NEXT_SIBLING; moreover, the first and last child are connected to the father by FIRST_CHILD_OF and LAST_CHILD_OF.
I simply want to find a way to cycle them in order to create a single string which is "A B C D".
Is there a Cypher query capable of this?
neo4j cypher
neo4j cypher
asked Nov 12 '18 at 11:56
WallWall
828
828
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Creating your model
For the ease of possible further answers and solutions I note my graph creating statement:
CREATE
(ormText:OrmText {name: 'orm_Text'})<-[:FIRST_CHILD_OF]-(letterA:Letter {name: 'A'}),
(letterA)-[:NEXT]->(letterB:Letter {name: 'B'}),
(letterA)-[:NEXT_SIBLING]->(letterB),
(letterB)-[:NEXT]->(letterC:Letter {name: 'C'}),
(letterB)-[:NEXT_SIBLING]->(letterC),
(letterC)-[:NEXT]->(letterD:Letter {name: 'D'}),
(letterC)-[:NEXT_SIBLING]->(letterD),
(letterD)-[:LAST_CHILD_OF]->(ormText);
Solution
MATCH
letterPath = (startLetter)-[:NEXT|NEXT_SIBLING*]->(endLetter)
WHERE
(startLetter)-[:FIRST_CHILD_OF]->(:OrmText)<-[:LAST_CHILD_OF]-(endLetter)
WITH nodes(letterPath) AS letterNodes
UNWIND letterNodes AS letterNode
RETURN DISTINCT letterNode.name AS letterName;
The second line detects the startLetter
as first child of orm_Text
and the endLetter
as last child of orm_Text
.
In line five the path between the start and end letter is calculated, its nodes were extracted in line six. Line seven creates singles nodes and line eight finally returns the result.
Note: By writing -[:NEXT|NEX_SIBLING*]->
a relationship of type NEXT
or NEXT_SIBLING
is valid for a match. If your requirement only need one specific type, remove the other and the |
.
Result
╒════════════╕
│"letterName"│
╞════════════╡
│"A" │
├────────────┤
│"B" │
├────────────┤
│"C" │
├────────────┤
│"D" │
└────────────┘
Extension
If you prefer your output in a single String
instead of a list of node names have a look at the following solution.
Solution
MATCH
letterPath = (startLetter)-[:NEXT|NEXT_SIBLING*]->(endLetter)
WHERE
(startLetter)-[:FIRST_CHILD_OF]->(:OrmText)<-[:LAST_CHILD_OF]-(endLetter)
WITH nodes(letterPath) AS letterNodes
RETURN DISTINCT reduce(s=head(letterNodes).name, n in tail(letterNodes) | s+" -> "+n.name) AS letterString;
Result
╒══════════════════╕
│"letterString" │
╞══════════════════╡
│"A -> B -> C -> D"│
└──────────────────┘
Thanks, I understand the approach and I'm sure it's correct, but I got the error "VariableormText
not defined ". Even creating a new MATCH at the beginning with this var, returns 0 records. Am I missing something?
– Wall
Nov 13 '18 at 14:13
1
@Wall Sorry, it was my fault. During the optimization something slightly screwed up. I corrected bothMATCH
statements, now the rendered result should be displayed again.
– ThirstForKnowledge
Nov 13 '18 at 16:27
@Wall I hope it works for you now and solves your challenge?
– ThirstForKnowledge
Nov 13 '18 at 16:31
1
To return properties of theOrmText
label, you must specify the node variable first and loop it through eachWITH
clause. Solution:MATCH letterPath = (ormText:OrmText)<-[FIRST_CHILD_OF]-(startLetter:Letter)-[:NEXT|NEXT_SIBLING*]->(endLetter:Letter)-[LAST_CHILD_OF]->(ormText) WITH nodes(letterPath) AS letterNodes, ormText.name AS ormTextName WITH filter(x IN letterNodes WHERE NOT (x:OrmText)) AS letterNodes, ormTextName RETURN DISTINCT reduce(s = head(letterNodes).name, n IN tail(letterNodes) | s + ' -> ' + n.name) AS letterString, ormTextName;
.
– ThirstForKnowledge
Nov 13 '18 at 18:59
1
This results in{ "letterString“: "A -> B -> C -> D" }, { "ormTextName" : "orm_Text" }
.
– ThirstForKnowledge
Nov 13 '18 at 19:01
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261672%2fneo4j-loop-for-all-children%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Creating your model
For the ease of possible further answers and solutions I note my graph creating statement:
CREATE
(ormText:OrmText {name: 'orm_Text'})<-[:FIRST_CHILD_OF]-(letterA:Letter {name: 'A'}),
(letterA)-[:NEXT]->(letterB:Letter {name: 'B'}),
(letterA)-[:NEXT_SIBLING]->(letterB),
(letterB)-[:NEXT]->(letterC:Letter {name: 'C'}),
(letterB)-[:NEXT_SIBLING]->(letterC),
(letterC)-[:NEXT]->(letterD:Letter {name: 'D'}),
(letterC)-[:NEXT_SIBLING]->(letterD),
(letterD)-[:LAST_CHILD_OF]->(ormText);
Solution
MATCH
letterPath = (startLetter)-[:NEXT|NEXT_SIBLING*]->(endLetter)
WHERE
(startLetter)-[:FIRST_CHILD_OF]->(:OrmText)<-[:LAST_CHILD_OF]-(endLetter)
WITH nodes(letterPath) AS letterNodes
UNWIND letterNodes AS letterNode
RETURN DISTINCT letterNode.name AS letterName;
The second line detects the startLetter
as first child of orm_Text
and the endLetter
as last child of orm_Text
.
In line five the path between the start and end letter is calculated, its nodes were extracted in line six. Line seven creates singles nodes and line eight finally returns the result.
Note: By writing -[:NEXT|NEX_SIBLING*]->
a relationship of type NEXT
or NEXT_SIBLING
is valid for a match. If your requirement only need one specific type, remove the other and the |
.
Result
╒════════════╕
│"letterName"│
╞════════════╡
│"A" │
├────────────┤
│"B" │
├────────────┤
│"C" │
├────────────┤
│"D" │
└────────────┘
Extension
If you prefer your output in a single String
instead of a list of node names have a look at the following solution.
Solution
MATCH
letterPath = (startLetter)-[:NEXT|NEXT_SIBLING*]->(endLetter)
WHERE
(startLetter)-[:FIRST_CHILD_OF]->(:OrmText)<-[:LAST_CHILD_OF]-(endLetter)
WITH nodes(letterPath) AS letterNodes
RETURN DISTINCT reduce(s=head(letterNodes).name, n in tail(letterNodes) | s+" -> "+n.name) AS letterString;
Result
╒══════════════════╕
│"letterString" │
╞══════════════════╡
│"A -> B -> C -> D"│
└──────────────────┘
Thanks, I understand the approach and I'm sure it's correct, but I got the error "VariableormText
not defined ". Even creating a new MATCH at the beginning with this var, returns 0 records. Am I missing something?
– Wall
Nov 13 '18 at 14:13
1
@Wall Sorry, it was my fault. During the optimization something slightly screwed up. I corrected bothMATCH
statements, now the rendered result should be displayed again.
– ThirstForKnowledge
Nov 13 '18 at 16:27
@Wall I hope it works for you now and solves your challenge?
– ThirstForKnowledge
Nov 13 '18 at 16:31
1
To return properties of theOrmText
label, you must specify the node variable first and loop it through eachWITH
clause. Solution:MATCH letterPath = (ormText:OrmText)<-[FIRST_CHILD_OF]-(startLetter:Letter)-[:NEXT|NEXT_SIBLING*]->(endLetter:Letter)-[LAST_CHILD_OF]->(ormText) WITH nodes(letterPath) AS letterNodes, ormText.name AS ormTextName WITH filter(x IN letterNodes WHERE NOT (x:OrmText)) AS letterNodes, ormTextName RETURN DISTINCT reduce(s = head(letterNodes).name, n IN tail(letterNodes) | s + ' -> ' + n.name) AS letterString, ormTextName;
.
– ThirstForKnowledge
Nov 13 '18 at 18:59
1
This results in{ "letterString“: "A -> B -> C -> D" }, { "ormTextName" : "orm_Text" }
.
– ThirstForKnowledge
Nov 13 '18 at 19:01
|
show 2 more comments
Creating your model
For the ease of possible further answers and solutions I note my graph creating statement:
CREATE
(ormText:OrmText {name: 'orm_Text'})<-[:FIRST_CHILD_OF]-(letterA:Letter {name: 'A'}),
(letterA)-[:NEXT]->(letterB:Letter {name: 'B'}),
(letterA)-[:NEXT_SIBLING]->(letterB),
(letterB)-[:NEXT]->(letterC:Letter {name: 'C'}),
(letterB)-[:NEXT_SIBLING]->(letterC),
(letterC)-[:NEXT]->(letterD:Letter {name: 'D'}),
(letterC)-[:NEXT_SIBLING]->(letterD),
(letterD)-[:LAST_CHILD_OF]->(ormText);
Solution
MATCH
letterPath = (startLetter)-[:NEXT|NEXT_SIBLING*]->(endLetter)
WHERE
(startLetter)-[:FIRST_CHILD_OF]->(:OrmText)<-[:LAST_CHILD_OF]-(endLetter)
WITH nodes(letterPath) AS letterNodes
UNWIND letterNodes AS letterNode
RETURN DISTINCT letterNode.name AS letterName;
The second line detects the startLetter
as first child of orm_Text
and the endLetter
as last child of orm_Text
.
In line five the path between the start and end letter is calculated, its nodes were extracted in line six. Line seven creates singles nodes and line eight finally returns the result.
Note: By writing -[:NEXT|NEX_SIBLING*]->
a relationship of type NEXT
or NEXT_SIBLING
is valid for a match. If your requirement only need one specific type, remove the other and the |
.
Result
╒════════════╕
│"letterName"│
╞════════════╡
│"A" │
├────────────┤
│"B" │
├────────────┤
│"C" │
├────────────┤
│"D" │
└────────────┘
Extension
If you prefer your output in a single String
instead of a list of node names have a look at the following solution.
Solution
MATCH
letterPath = (startLetter)-[:NEXT|NEXT_SIBLING*]->(endLetter)
WHERE
(startLetter)-[:FIRST_CHILD_OF]->(:OrmText)<-[:LAST_CHILD_OF]-(endLetter)
WITH nodes(letterPath) AS letterNodes
RETURN DISTINCT reduce(s=head(letterNodes).name, n in tail(letterNodes) | s+" -> "+n.name) AS letterString;
Result
╒══════════════════╕
│"letterString" │
╞══════════════════╡
│"A -> B -> C -> D"│
└──────────────────┘
Thanks, I understand the approach and I'm sure it's correct, but I got the error "VariableormText
not defined ". Even creating a new MATCH at the beginning with this var, returns 0 records. Am I missing something?
– Wall
Nov 13 '18 at 14:13
1
@Wall Sorry, it was my fault. During the optimization something slightly screwed up. I corrected bothMATCH
statements, now the rendered result should be displayed again.
– ThirstForKnowledge
Nov 13 '18 at 16:27
@Wall I hope it works for you now and solves your challenge?
– ThirstForKnowledge
Nov 13 '18 at 16:31
1
To return properties of theOrmText
label, you must specify the node variable first and loop it through eachWITH
clause. Solution:MATCH letterPath = (ormText:OrmText)<-[FIRST_CHILD_OF]-(startLetter:Letter)-[:NEXT|NEXT_SIBLING*]->(endLetter:Letter)-[LAST_CHILD_OF]->(ormText) WITH nodes(letterPath) AS letterNodes, ormText.name AS ormTextName WITH filter(x IN letterNodes WHERE NOT (x:OrmText)) AS letterNodes, ormTextName RETURN DISTINCT reduce(s = head(letterNodes).name, n IN tail(letterNodes) | s + ' -> ' + n.name) AS letterString, ormTextName;
.
– ThirstForKnowledge
Nov 13 '18 at 18:59
1
This results in{ "letterString“: "A -> B -> C -> D" }, { "ormTextName" : "orm_Text" }
.
– ThirstForKnowledge
Nov 13 '18 at 19:01
|
show 2 more comments
Creating your model
For the ease of possible further answers and solutions I note my graph creating statement:
CREATE
(ormText:OrmText {name: 'orm_Text'})<-[:FIRST_CHILD_OF]-(letterA:Letter {name: 'A'}),
(letterA)-[:NEXT]->(letterB:Letter {name: 'B'}),
(letterA)-[:NEXT_SIBLING]->(letterB),
(letterB)-[:NEXT]->(letterC:Letter {name: 'C'}),
(letterB)-[:NEXT_SIBLING]->(letterC),
(letterC)-[:NEXT]->(letterD:Letter {name: 'D'}),
(letterC)-[:NEXT_SIBLING]->(letterD),
(letterD)-[:LAST_CHILD_OF]->(ormText);
Solution
MATCH
letterPath = (startLetter)-[:NEXT|NEXT_SIBLING*]->(endLetter)
WHERE
(startLetter)-[:FIRST_CHILD_OF]->(:OrmText)<-[:LAST_CHILD_OF]-(endLetter)
WITH nodes(letterPath) AS letterNodes
UNWIND letterNodes AS letterNode
RETURN DISTINCT letterNode.name AS letterName;
The second line detects the startLetter
as first child of orm_Text
and the endLetter
as last child of orm_Text
.
In line five the path between the start and end letter is calculated, its nodes were extracted in line six. Line seven creates singles nodes and line eight finally returns the result.
Note: By writing -[:NEXT|NEX_SIBLING*]->
a relationship of type NEXT
or NEXT_SIBLING
is valid for a match. If your requirement only need one specific type, remove the other and the |
.
Result
╒════════════╕
│"letterName"│
╞════════════╡
│"A" │
├────────────┤
│"B" │
├────────────┤
│"C" │
├────────────┤
│"D" │
└────────────┘
Extension
If you prefer your output in a single String
instead of a list of node names have a look at the following solution.
Solution
MATCH
letterPath = (startLetter)-[:NEXT|NEXT_SIBLING*]->(endLetter)
WHERE
(startLetter)-[:FIRST_CHILD_OF]->(:OrmText)<-[:LAST_CHILD_OF]-(endLetter)
WITH nodes(letterPath) AS letterNodes
RETURN DISTINCT reduce(s=head(letterNodes).name, n in tail(letterNodes) | s+" -> "+n.name) AS letterString;
Result
╒══════════════════╕
│"letterString" │
╞══════════════════╡
│"A -> B -> C -> D"│
└──────────────────┘
Creating your model
For the ease of possible further answers and solutions I note my graph creating statement:
CREATE
(ormText:OrmText {name: 'orm_Text'})<-[:FIRST_CHILD_OF]-(letterA:Letter {name: 'A'}),
(letterA)-[:NEXT]->(letterB:Letter {name: 'B'}),
(letterA)-[:NEXT_SIBLING]->(letterB),
(letterB)-[:NEXT]->(letterC:Letter {name: 'C'}),
(letterB)-[:NEXT_SIBLING]->(letterC),
(letterC)-[:NEXT]->(letterD:Letter {name: 'D'}),
(letterC)-[:NEXT_SIBLING]->(letterD),
(letterD)-[:LAST_CHILD_OF]->(ormText);
Solution
MATCH
letterPath = (startLetter)-[:NEXT|NEXT_SIBLING*]->(endLetter)
WHERE
(startLetter)-[:FIRST_CHILD_OF]->(:OrmText)<-[:LAST_CHILD_OF]-(endLetter)
WITH nodes(letterPath) AS letterNodes
UNWIND letterNodes AS letterNode
RETURN DISTINCT letterNode.name AS letterName;
The second line detects the startLetter
as first child of orm_Text
and the endLetter
as last child of orm_Text
.
In line five the path between the start and end letter is calculated, its nodes were extracted in line six. Line seven creates singles nodes and line eight finally returns the result.
Note: By writing -[:NEXT|NEX_SIBLING*]->
a relationship of type NEXT
or NEXT_SIBLING
is valid for a match. If your requirement only need one specific type, remove the other and the |
.
Result
╒════════════╕
│"letterName"│
╞════════════╡
│"A" │
├────────────┤
│"B" │
├────────────┤
│"C" │
├────────────┤
│"D" │
└────────────┘
Extension
If you prefer your output in a single String
instead of a list of node names have a look at the following solution.
Solution
MATCH
letterPath = (startLetter)-[:NEXT|NEXT_SIBLING*]->(endLetter)
WHERE
(startLetter)-[:FIRST_CHILD_OF]->(:OrmText)<-[:LAST_CHILD_OF]-(endLetter)
WITH nodes(letterPath) AS letterNodes
RETURN DISTINCT reduce(s=head(letterNodes).name, n in tail(letterNodes) | s+" -> "+n.name) AS letterString;
Result
╒══════════════════╕
│"letterString" │
╞══════════════════╡
│"A -> B -> C -> D"│
└──────────────────┘
edited Nov 13 '18 at 16:22
answered Nov 12 '18 at 13:52
ThirstForKnowledgeThirstForKnowledge
6551112
6551112
Thanks, I understand the approach and I'm sure it's correct, but I got the error "VariableormText
not defined ". Even creating a new MATCH at the beginning with this var, returns 0 records. Am I missing something?
– Wall
Nov 13 '18 at 14:13
1
@Wall Sorry, it was my fault. During the optimization something slightly screwed up. I corrected bothMATCH
statements, now the rendered result should be displayed again.
– ThirstForKnowledge
Nov 13 '18 at 16:27
@Wall I hope it works for you now and solves your challenge?
– ThirstForKnowledge
Nov 13 '18 at 16:31
1
To return properties of theOrmText
label, you must specify the node variable first and loop it through eachWITH
clause. Solution:MATCH letterPath = (ormText:OrmText)<-[FIRST_CHILD_OF]-(startLetter:Letter)-[:NEXT|NEXT_SIBLING*]->(endLetter:Letter)-[LAST_CHILD_OF]->(ormText) WITH nodes(letterPath) AS letterNodes, ormText.name AS ormTextName WITH filter(x IN letterNodes WHERE NOT (x:OrmText)) AS letterNodes, ormTextName RETURN DISTINCT reduce(s = head(letterNodes).name, n IN tail(letterNodes) | s + ' -> ' + n.name) AS letterString, ormTextName;
.
– ThirstForKnowledge
Nov 13 '18 at 18:59
1
This results in{ "letterString“: "A -> B -> C -> D" }, { "ormTextName" : "orm_Text" }
.
– ThirstForKnowledge
Nov 13 '18 at 19:01
|
show 2 more comments
Thanks, I understand the approach and I'm sure it's correct, but I got the error "VariableormText
not defined ". Even creating a new MATCH at the beginning with this var, returns 0 records. Am I missing something?
– Wall
Nov 13 '18 at 14:13
1
@Wall Sorry, it was my fault. During the optimization something slightly screwed up. I corrected bothMATCH
statements, now the rendered result should be displayed again.
– ThirstForKnowledge
Nov 13 '18 at 16:27
@Wall I hope it works for you now and solves your challenge?
– ThirstForKnowledge
Nov 13 '18 at 16:31
1
To return properties of theOrmText
label, you must specify the node variable first and loop it through eachWITH
clause. Solution:MATCH letterPath = (ormText:OrmText)<-[FIRST_CHILD_OF]-(startLetter:Letter)-[:NEXT|NEXT_SIBLING*]->(endLetter:Letter)-[LAST_CHILD_OF]->(ormText) WITH nodes(letterPath) AS letterNodes, ormText.name AS ormTextName WITH filter(x IN letterNodes WHERE NOT (x:OrmText)) AS letterNodes, ormTextName RETURN DISTINCT reduce(s = head(letterNodes).name, n IN tail(letterNodes) | s + ' -> ' + n.name) AS letterString, ormTextName;
.
– ThirstForKnowledge
Nov 13 '18 at 18:59
1
This results in{ "letterString“: "A -> B -> C -> D" }, { "ormTextName" : "orm_Text" }
.
– ThirstForKnowledge
Nov 13 '18 at 19:01
Thanks, I understand the approach and I'm sure it's correct, but I got the error "Variable
ormText
not defined ". Even creating a new MATCH at the beginning with this var, returns 0 records. Am I missing something?– Wall
Nov 13 '18 at 14:13
Thanks, I understand the approach and I'm sure it's correct, but I got the error "Variable
ormText
not defined ". Even creating a new MATCH at the beginning with this var, returns 0 records. Am I missing something?– Wall
Nov 13 '18 at 14:13
1
1
@Wall Sorry, it was my fault. During the optimization something slightly screwed up. I corrected both
MATCH
statements, now the rendered result should be displayed again.– ThirstForKnowledge
Nov 13 '18 at 16:27
@Wall Sorry, it was my fault. During the optimization something slightly screwed up. I corrected both
MATCH
statements, now the rendered result should be displayed again.– ThirstForKnowledge
Nov 13 '18 at 16:27
@Wall I hope it works for you now and solves your challenge?
– ThirstForKnowledge
Nov 13 '18 at 16:31
@Wall I hope it works for you now and solves your challenge?
– ThirstForKnowledge
Nov 13 '18 at 16:31
1
1
To return properties of the
OrmText
label, you must specify the node variable first and loop it through each WITH
clause. Solution: MATCH letterPath = (ormText:OrmText)<-[FIRST_CHILD_OF]-(startLetter:Letter)-[:NEXT|NEXT_SIBLING*]->(endLetter:Letter)-[LAST_CHILD_OF]->(ormText) WITH nodes(letterPath) AS letterNodes, ormText.name AS ormTextName WITH filter(x IN letterNodes WHERE NOT (x:OrmText)) AS letterNodes, ormTextName RETURN DISTINCT reduce(s = head(letterNodes).name, n IN tail(letterNodes) | s + ' -> ' + n.name) AS letterString, ormTextName;
.– ThirstForKnowledge
Nov 13 '18 at 18:59
To return properties of the
OrmText
label, you must specify the node variable first and loop it through each WITH
clause. Solution: MATCH letterPath = (ormText:OrmText)<-[FIRST_CHILD_OF]-(startLetter:Letter)-[:NEXT|NEXT_SIBLING*]->(endLetter:Letter)-[LAST_CHILD_OF]->(ormText) WITH nodes(letterPath) AS letterNodes, ormText.name AS ormTextName WITH filter(x IN letterNodes WHERE NOT (x:OrmText)) AS letterNodes, ormTextName RETURN DISTINCT reduce(s = head(letterNodes).name, n IN tail(letterNodes) | s + ' -> ' + n.name) AS letterString, ormTextName;
.– ThirstForKnowledge
Nov 13 '18 at 18:59
1
1
This results in
{ "letterString“: "A -> B -> C -> D" }, { "ormTextName" : "orm_Text" }
.– ThirstForKnowledge
Nov 13 '18 at 19:01
This results in
{ "letterString“: "A -> B -> C -> D" }, { "ormTextName" : "orm_Text" }
.– ThirstForKnowledge
Nov 13 '18 at 19:01
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261672%2fneo4j-loop-for-all-children%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown