Simple operation of adding, deleting, modifying and checking neo4j

create node

create (a:Person{name:"yare",age:25}) 

create (b:Person{name:"ivy",age:26}) 

 

Returns the id of the created node

create (a:org{name:"juxinli"}) return ID(a)

 

query node

match (m:Person) return m

match (m: Person {name:"yare"}) return m

 

Query the users that juxinli follows and return the user node

match (o: org{name:"juxinli"})-[rel:observer]->(p)  return p

match (n) where name = ivy return n limit 1

get id

match (m: Person {name:"ivy"}) return m,ID(m)

query by id

match (n) where ID(n) = 17846 return n limit 1

Query by relationship

Match (n:org)-[:observer]->(end:person) where n.name='juxinli'  return end

Match (n:org)-[r:observer]->(p:person) where n.name='juxinli' and p.name='maomao'  return p

Match (n:org)-[r:observer]->(p:person) where n.name='juxinli' and p.name='yare' return p

 

Build relationships

CREATE (p1)-[:oberver]->(p2)

 

eg:

match (n:org { name: 'juxinli' }) return n

match (p:person { name: 'maomao' }) return p

create (n) -[:observer]->(p) return n,p

Create a relationship with attributes

create (a:person {name:"zhangyan"})-[r:observer {status:1,time:'2017-02-23 12:12:12'}]->(o:org {name:"juxinli"})

Match (a:person{name:"zhangyan"}) return a

 

start a=node(8),b=node(7) create (a)-[n:observer]->(b)return n

Match (o:org{name:"juxinli"}) return o 

 

 

MATCH (o)-[rel:observer {status:1,time:'2017-02-23 12:12:12'}]->(p) 

WHERE p.name='juxinli' and o.name = 'zhangyan'

return o

 

 

delete all nodes

start n=node(*)  match (n)-[r:observer]-()  delete n,r

match (o:org{name:"juxinli"}) match (n)-[r:observer]-()  delete o,r

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326353664&siteId=291194637