0

Suppose I have a set of Nodes in Neo4j db as bellow:

CREATE (n:A { p1 : 2 })   //call this a1
CREATE (n:A { p1 : 3 })   // call this a2
CREATE (n:A { p1 : 8 })   // call this a3

Now I want to query this db and create another set of nodes and edges as the following:

For each node labeled A whose p1 property is less than 5, create a new node with a label QA and connect this node to its origin (the A labeled node it comes from). Is it possible to directly encode this with Neo4j query language?

In other words, in the above db state, executing the query will create two nodes, namely qa1, and qa2, and will connect them with a1 and a2 with edges, say of type isA.

Here is the same question for OrientDB

Community
  • 1
  • 1
qartal
  • 2,024
  • 19
  • 31

1 Answers1

1

For sure it is possible :

MATCH (n:A)
WHERE n.p1 < 5
CREATE (qa:QA)-[:IS_A]->(n)
Christophe Willemsen
  • 19,399
  • 2
  • 29
  • 36