Select and insert by keeping references in Neo4J

允我心安 提交于 2019-12-25 03:15:56

问题


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


回答1:


For sure it is possible :

MATCH (n:A)
WHERE n.p1 < 5
CREATE (qa:QA)-[:IS_A]->(n)


来源:https://stackoverflow.com/questions/29987512/select-and-insert-by-keeping-references-in-neo4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!