NEO4J: Graph database Graphdb (iii)

Source: Internet
Author: User
Tags neo4j

This film continues the previous several introduction diagram database creation, has the question can I look at the previous two articles: http://www.cnblogs.com/rongyux/p/5537206.html

Four-figure database creation

1 Create a node person {name: "My name"}

" My Name " return me;

" Mystic River ", Released:1993}) RETURN movie;

2 Modifying properties

Change properties: movie.tagline = "We bury Our sins here, Dave. We wash them clean. "

MATCH (Movie:movie) WHERE movie.title="mysticRiver""We Bury our sins here, Dave. We wash them clean. " RETURN movie;

Change: movie.released = 2003

MATCH (Movie:movie) WHERE movie.title="mysticRiver"2003  RETURN movie;

3 Increase relationship-side

MATCH (Me:person), (Movie:movie)      WHERE me.name="My name"  and       movie.title="Mystic River  "CREATE (Me)-[:reviewed {rating:summary:"tragic character Movie"}]-> (movie);

Another way to do this:

MATCH (Me:person {name:"My name"}),       (Movie:movie {title:"  MysticRiver"})      CREATE (Me)-[:reviewed {rating:summary:"  Tragic character movie"}]-> (movie);

4merge: If this side is not present, increase the relationship:

MATCH (Clint:person), (Mystic:movie)      WHERE clint.name="Clint Eastwood" and mystic.title="mystic River " MERGE (Clint)-[:D irected]->(mystic) RETURN Clint, mystic;

A more complicated example:

Increased understanding knows relationship: A film actor and actor, actor or director, or director and Director may know:

MATCH (a)-[:acted_in|:D Irected]-> () <-[:acted_in|:D irected]-(b) WHERE not (a)-[:knows]-(b) MERGE (a)-[:knows]-> (b);

5 deleting nodes and edges

Match (Me:person {name="My name"}) OPTIONAL match (Me)-[r]-() DELETE me,r;

6 Length level output

MATCH (Node1)-[*]-(Node2)

eg MATCH (Node1)-[*1..3]-(node2): output of three length levels

shortestPathThe 7 function returns the path with the shortest route length

MATCH P=shortestpath ((node1)-[*]-(node2))    RETURN Length (p), nodes (p)

NEO4J: Graph database Graphdb (iii)

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.