MATCH (u)-[:HAS_COMMENT]->(c:Comment)-[:MADE_ON]->(event:Event{eventId:'3582976151605248'}) where c.parentId ' '
WITH u, event, c, [(c)-[:HAS_CHILD*1..5]->(n:Comment)<-[:HAS_COMMENT]-(user)|n] AS children
WITH properties(u) as userDetails,
properties(c) as parent, children,
properties(user) as userChildDetails
RETURN {
parentComment: parent,
children: children,
userDetails: userDetails,
userChildDetails:userChildDetails
} AS comment
What is the question?
like this
"data": {
"getComments": [
{
"comment": "nice",
"eventId": "3582976151605248",
"createdAt": "Wed Feb 21 2024 12:20:31 GMT+0530 (India Standard Time)",
"updateAt": "Wed Feb 21 2024 12:20:31 GMT+0530 (India Standard Time)",
"userId": "A8nfKwZP8OUwDXfXhjgyduFKlPH3",
"publicId": "3582980485697536",
"parentId": "",
"children": [
{
"eventId": "3582976151605248",
"comment": "child",
"publicId": "3582980531941376",
"parentId": "3582980485697536",
"userId": "A8nfKwZP8OUwDXfXhjgyduFKlPH3",
userDetails:{
}
children:[ {
"eventId": "3582976151605248",
"comment": "child2",
"publicId": "3582980531941378",
"parentId": "3582980531941376",
"userId": "A8nfKwZP8OUwDXfXhjgyduFKlPH3"
userDetails:{
}
}
]
}
],
"userDetails": {
"name": "shubham",
"userId": "A8nfKwZP8OUwDXfXhjgyduFKlPH3"
}
}, ]
You are not extracting the user info when extracting the child comments. You can change what is returned in your list comprehension to include the user for the comment.
MATCH (u)-[:HAS_COMMENT]->(c:Comment)-[:MADE_ON]->(event:Event{eventId:'3582976151605248'}) where c.parentId ' '
WITH u, event, c, [(c)-[:HAS_CHILD*1..5]->(n:Comment)<-[:HAS_COMMENT]-(user)|n{.*, userDetails: properties(user)}] AS children
WITH properties(u) as userDetails,
properties(c) as parent, children,
properties(user) as userChildDetails
RETURN {
parentComment: parent,
children: children,
userDetails: userDetails,
userChildDetails:userChildDetails
} AS comment
how to managae multiple children
The children variable is a list. Did the change I suggested work? If not, what specifically did not work? Also, can you provide the output? It is hard for me to visualize the data? Or, can yo provide a script to generate some test data?
i want this type output
{
"comment": "nice",
"eventId": "3582976151605248",
"userId": "A8nfKwZP8OUwDXfXhjgyduFKlPH3",
"publicId": "3582980485697536",
"parentId": "",
"userDetails": {
"userId": "A8nfKwZP8OUwDXfXhjgyduFKlPH3",
"name": "shubham",
"email": "shubham@gmail.com"
},
"children": [
{
"eventId": "3582976151605248",
"parentId": "3582980485697536",
"publicId": "3582980531941376",
"userId": "A8nfKwZP8OUwDXfXhjgyduFKlPH3",
"comment": "child",
"userDetails": {
"userId": "A8nfKwZP8OUwDXfXhjgyduFKlPH3",
"name": "shubham",
"email": "shubham@gmail.com",
"image": "ab.jpg"
},
"children": [
{
"eventId": "3582976151605248",
"parentId": "3582980531941376",
"publicId": "3583032508395520",
"userId": "ORwLXgeA76fhEeCMZJAm0laYxXl1",
"comment": "child2",
"userDetails": {
"userId": "ORwLXgeA76fhEeCMZJAm0laYxXl1",
"name": "veerendra",
"email": "veerendra@gmail.com",
"image": "ab.jpg"
}
}]
}
]
}