Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-21-2023 05:53 AM
I have a neo4j database up and running. I also have a process that runs every 5 minutes and what it does is to create nodes of type "Point".
"Point" has the following properties:
pointId, cameraId, classId, groupId, datetime
Nodes of type "Point" relate to themself if: pointId & cameraId & classId & groupId are the same.
Is it possible to somehow get all the nodes "Point" that relate themself and based on that group of nodes create a new node "Line" where "Line"-[:CONTAINS]->"Point"?
UPDATE: Following image shows what I have and what I need. For simplicity, I've just defined the property "camera", if a node Point shares the camera then it needs to be grouped.
01-21-2023 09:28 AM
I am a little confused. You diagram looks like you want to group nodes with the same cameraId into a group related to a Line node. The query below achieves this. It groups all the Point nodes by values of cameraId. It then creates a Line node (I added the id = cameraId of the group for tracking) and relates all the nodes to this node that have the same cameraId.
match(p:Point)
with p.cameraId as cameraId, collect(p) as group
merge(l:Line{id: cameraId})
forEach(i in group |
merge(l)-[:CONTAINS]->(i)
)
Is this what you are looking for?
01-21-2023 09:59 AM
thank you the above one is looking good but my requirement is the newly created node shouldn't have any property except UUID and my nodes are having different properties
01-21-2023 10:17 AM
How about this:
match(p:Point)
with p.cameraId as cameraId, collect(p) as group
merge(l:Line{uuid: apoc.create.uuid()})
forEach(i in group |
merge(l)-[:CONTAINS]->(i)
)
You need the apoc library installed.
All the sessions of the conference are now available online