Neo4J Lab Create Node and Relationships Day 1

 Neo4J lab - Running Beginner Query/ Code



Work with  Nodes


//Create a Node:

  • CREATE (n)

Create node in Neo4J algaestudy





//View the nodes

  • match (n) return (n)


match (n) return (n)








//Create a Node and view results:

  • CREATE (n)
  • with n
  • match (n) return(n)

Create node and view results









//Creating multiple nodes is done by separating them with a comma.

  • CREATE (n), (m)

Creating multiple nodes is done by separating them with a comma.




//Create a node with a label:

//To add a label when creating a node, use the syntax below:

  • CREATE (n:Person)
  • with n
  • match (n) return(n)

//Create a node with a label:  //To add a label when creating a node, use the syntax below:







//Create a node with multiple labels:

//To add labels when creating a node, use the syntax below. In this case, we add two labels.

  • CREATE (n:Person:Swedish)


CREATE (n:Person:Swedish)








//Create node and add labels and properties:

//When creating a new node with labels, you can add properties at the same time.

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


//Create node and add labels and properties:  //When creating a new node with labels, you can add properties at the same time.









//Return created node:

//Creating a single node is done by issuing the following query:

  • CREATE (a {name: 'Andy'})
  • RETURN a.name


//Return created node:  //Creating a single node is done by issuing the following query:




Create Relationships


  • Create a relationship between two nodes:
    • To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them.




// Create label and setup relationship
  • Create (a:person{name:'sumit'})
  • Create (b:person{name:'amit'})
  • with a , b
  • MATCH // set condition
  •   (a:person),
  •   (b:person)
  • WHERE a.name = 'sumit' AND b.name = 'amit'
  • CREATE (a)-[r:FRIENDS]->(b) //set relationship
  • RETURN type(r)




 





//Create a relationship and set properties
//Setting properties on relationships is done in a similar manner to how it’s done when creating nodes. //Note that the values can be any expression.
  • // Create label and setup relationship
  • Create (a:person{name:'sumit'})
  • Create (b:person{name:'amit'})
  • with a , b
  • MATCH  // set condition
  •   (a:person),
  •   (b:person)
  • WHERE a.name = 'sumit' AND b.name = 'amit'
  • //set relationship
  • CREATE (a)-[r:frnds {name: a.name + '<->' + b.name}]->(b)
  • RETURN type(r), r.name



// Create label and setup relationship Create (a:person{name:'sumit'}) Create (b:person{name:'amit'}) with a , b MATCH  // set condition   (a:person),   (b:person) WHERE a.name = 'sumit' AND b.name = 'amit' //set relationship CREATE (a)-[r:frnds {name: a.name + '<->' + b.name}]->(b) RETURN type(r), r.name

//Create a relationship and set properties //Setting properties on relationships is done in a similar manner to how it’s done when creating nodes. //Note that the values can be any expression. // Create label and setup relationship Create (a:person{name:'sumit'}) Create (b:person{name:'amit'}) with a , b MATCH  // set condition   (a:person),   (b:person) WHERE a.name = 'sumit' AND b.name = 'amit' //set relationship CREATE (a)-[r:frnds {name: a.name + '<->' + b.name}]->(b) RETURN type(r), r.name









//Create a full path
//When you use CREATE and a pattern, all parts of the pattern that are not already in scope at this time will be created. 
//This query creates three nodes and two relationships in one go, assigns it to a path variable, and returns it.


  • CREATE p = (:person {name:'andy'})-[:WORKS_AT]->(:company {name: 'Neo4j'})<-[:WORKS_AT]-(:person {name: 'Michael'})
  • RETURN p


//This query creates three nodes and two relationships in one go, assigns it to a path variable, and returns it.








No comments:
Write comments

Please do not enter spam links

Meet US

Services

More Services