美文网首页
neo4j cypher-create

neo4j cypher-create

作者: 飞跑的蛤蟆 | 来源:发表于2020-10-30 15:43 被阅读0次

    一、 create 创建

    1. create nodes 创建节点

    1.1 创建单个节点

    create (n)
    

    Created 1 node, completed after 2 ms.

    1.2 创建多个节点

    create (n), (m)
    

    Created 2 nodes, completed after 2 ms.

    1.3 创建带有标签的节点

    create(n:Person)
    

    Added 1 label, created 1 node, completed after 4 ms.

    1.4 创建具有多个标签的节点

    create(n:Person:Swedish)
    

    Added 2 labels, created 1 node, completed after 2 ms.

    1.5 创建节点并添加标签和属性

    create (n:Person {name:'Andy', title:'Developer'})
    

    Added 1 label, created 1 node, set 2 properties, completed after 43 ms.

    1.6 返回创建的节点

    这会创建一个节点

    create (a {name:'Andy'}) return a.name
    

    Created 1 node, set 1 property, started streaming 1 records after 2 ms and completed after 3 ms.

    2. create relationships 创建关系

    2.1 在两个节点之间建立关系

    前置操作:

    create (a:Person {name:'A'}), (b:Person {name:'B'})
    

    Added 2 labels, created 2 nodes, set 2 properties, completed after 18 ms.

    match (a:Person), (b:Person)
    where a.name = 'A' and b.name = 'B'
    create (a)-[r:RELTYPE]->(b)
    return type(r)
    

    Created 1 relationship, started streaming 1 records after 1 ms and completed after 62 ms.

    2.2 创建关系并设置属性

    match (a:Person), (b:Person)
    where a.name = 'A' and b.name = 'B'
    create (a)-[r:RELTYPE {name:a.name + '<->' + b.name}]->(b)
    return type(r), r.name
    

    Set 1 property, created 1 relationship, started streaming 1 records after 3 ms and completed after 10 ms.

    3. create a full path 创建一个完整的路径

    create p =(andy {name:'Andy'})-[:WORKS_AT]->(neo)<-[:WORKS_AT]-(michael {name:'Michael'})
    return p
    

    Displaying 3 nodes, 2 relationships

    <img src="https://i.loli.net/2020/10/28/4IiolLBa3m6Ukqy.png" alt="image-20201028190228099" style="zoom:80%;" />

    4. use parameters with create 在创建时使用参数

    4.1 创建带有属性节点的参数

    {
        "props":{
            "name":"Andy",
            "position":"Developer"
        }
    }
    
    create (n:Person $props) return n
    

    cypher 中不能写 js,故不能执行成功

    create (n:Person {name:"Andy", position:"Developer"}) return n
    

    4.2 为多个节点的属性创建一个参数

    {
        "props":[
            {
                "name":"Andy",
                "position":"Developer"
            },
            {
                "name":"Michael",
                "position":"Developer"
            }
        ]
    }
    
    unwind $props as map
    create (n)
    set n = map
    

    cypher 中不能写 js,故不能执行成功

    unwind [{name:"Andy", position:"Developer"}, {name:"Michael", position:"Developer"}] as map create (n) set n = map return n
    

    相关文章

      网友评论

          本文标题:neo4j cypher-create

          本文链接:https://www.haomeiwen.com/subject/hfydvktx.html