Neo4j学习笔记六【Cypher操作图形数据】 发表于 2016-07-11 | 分类于 Neo4j Cypher更新图形数据创建新的USERS节点12create (n:USERS{name : 'Grace Spencer', yearOfBirth : 1982, email : 'grace@gmail.com'})return n; 创建关系1234match (john:USERS),(grace:USERS)where john.name = 'John Johnson' and grace.name = 'Grace Spencer'create (john)-[r:IS_FRIEND_OF]->(grace)return r; 同时创建新节点和关系12345678910111213141516171819match (john:USERS)where john.name = 'John Johnson'create (john)-[r:IS_FRIEND_OF]->(lee:USERS{name : 'Lee', yearOfBirth : 1990, email : 'lee@gmail.com'})return r,lee``` #### 删除数据```cypher//尝试执行上述代码会出错,Neo4j要求先删除关系start lee= node(10)delete lee;//明确删除一个节点和所有关联关系start lee = node(10)match (lee)-[r]-()delete lee,r//或者执行新的apiMATCH (lee:USERS { name:'Lee' })DETACH DELETE lee 更新节点属性1234match (john)where john.name = 'John Johnson'//若yearOfBirth属性不存在会创建该属性set john.yearOfBirth = 1973; 删除节点属性123match (john)where john.name = 'John Johnson'remove john.yearOfBirth; 高级Cypher聚合123match(user:USERS)-[:IS_FRIEND_OF]-()return user,count(*)order by count(*) desc; 函数查看每一类型有多少个关系开始于或结束于用户John123match (john:USERS{name:'John Johnson'})match (john)-[rel]-()return type(rel),count(*); with语句的管道功能,只查出多于一次的关系12345match (john:USERS{name:'John Johnson'})match (john)-[rel]-()with type(rel) as type, count(*) as countwhere count > 1return type, count;