-
Notifications
You must be signed in to change notification settings - Fork 0
Neo4j
illyfrancis edited this page Jul 26, 2013
·
6 revisions
Intro to Neo4j by Emil Eifram
- Nodes
- Relationships between nodes
- Properties on both
- First Identify the entities
- node id (mandatory attrib on a node)
- node attributes
- Nodes (Person) knows (relationships) other node
- Relationships also have properties (e.g. the "knows" has age = 3 days)
- can add arbitrary relationships "coded_by"
GraphDatabaseService graphDb = ... // get factory (via DI or whatever)
// create Thomas "Neo" Anderson
Node mrAnderson = graphDb.createNode();
mrAnderson.setProperty("name", "Thomas Anderson");
mrAnderson.setProperty("age", 29);
// create Morpheus
Node morpheus = graphDb.createNode();
morpheus.setProperty("name", "Morpheus");
morpheus.setProperty("rank", "Captain");
morpheus.setProperty("occupation", "Total bad ass");
// create a relationship representing that they know each other
mrAnderson.createRelationshipTo(morpheus, RelTypes.KNOWS);
// create Trinity, Cypher, Agent Smith, Architect similarly