NEO4J Database--cypher Language Beginner

Source: Internet
Author: User
Tags neo4j

Any database based on additions and deletions to the four functions, and neo4j use of the cypher language. Cypher is a very good language for working with graph databases, and here are some basic features to learn about his basic usage. Let's do a demonstration with our intelligent Motion Picture quiz System.

Create a Node

There are two ways to create a node, one is create, and the other is the merge method. Where created with Create is whether or not the node is created, and merge is no longer created if the node exists.

1 // merge mode, creating a unique node 2  34//Create mode, regardless of whether or not both are created node 5 creates (n: Godfather)

(The nodes that were created two times by create, their ID values are automatically assigned and incremented by neo4j) at this point the node created has no other attributes than the id attribute.

Two additions and deletions change node properties

(1) Find the appropriate node and return

1 // Be careful not to forget to return nodes 2 where 3272 return N

(2) Adding attributes to the corresponding node

1 // Add three attributes to this node, namely label (node label signature), ReleaseDate (release date), Introduction (film introduction) 2 where 3272 set n.label=' godfather ', n.releasedate='1991-03-21' , n.introduction=' godfather looks good 'return n

NEO4J query node: Match equals the Select of a relational database, which is equivalent to the find of a non-relational database MongoDB

NEO4J Modify node properties with: Set equivalent to the update...set of the relational database ...

(In neo4j, if you set a property that does not exist, the property will be created automatically)

(3) Deleting a node's properties

1 // Remove release date properties for a movie 2 where 3272 return N

(4) Creating a node with attributes

1 Create (n:movie{label:' godfather 'return n

Three fuzzy query

Query property value label begins with "teach" node information for any of the remaining values

where n.label=~' teaches *. ' return N

Four delete the corresponding node

Delete the node for the corresponding label in the node

where 3257 Delete n

Five relations

1. Create a relationship

A relationship cannot exist on its own, and must have two or more two nodes to be able. Instead of creating a unified create command, the creation of a relationship is virtually the same as creating a node, the only difference being that the relationship is directional and the relationship is denoted by ' [] ' and the node is represented by ' (') '. Such as:

where n.label=' Jet li ' and b.label=' Shaolin Temple 'Create (n)-[r: Actedin{since:1991, Champion:3return n,r,b

(1), first match found node N and b, that is, Jet Li and Shaolin Temple nodes node

(2), and then create a node N to Node B relationship R,r has two properties, one is time since, the other is the number of prizes received champion

(3), finally returns the result of the relationship between the N,r,b complete node, the table data has three columns.

2. Modifying relationship Properties

where 12513 set r.since='1990-09-09'return n,r,b

3. Delete a relationship

where n.label=' Jet li ' and b.label=' Shaolin Temple '  Delete Rreturn R

The above is the basic usage of cypher language.

Part of this article refers to "80402519"

NEO4J Database--cypher Language Beginner

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.