Adding relationship to existing nodes with Cypher

前端 未结 2 789
暖寄归人
暖寄归人 2020-12-12 20:34

I\'m trying out Neo4j for the first time. I\'m using the 2.0-RC1 community edition.

I\'ve created some nodes:

MERGE (u:User{username:\'admin\',passwo         


        
2条回答
  •  余生分开走
    2020-12-12 21:15

    In Neo4j 2.0 you can create schema indexes for your labels and the properties you use for lookup:

    CREATE INDEX ON :User(username)
    CREATE INDEX ON :Role(name)
    

    To create relationships you might use:

    MATCH (u:User {username:'admin'}), (r:Role {name:'ROLE_WEB_USER'})
    CREATE (u)-[:HAS_ROLE]->(r)
    

    The MATCH will use an index if possible. If there is no index, it will lookup up all nodes carrying the label and see if the property matches.

    N.B. the syntax above will only work with Neo4j 2.0.0-RC1 and above.

提交回复
热议问题