Skip to content

Instantly share code, notes, and snippets.

@okabasakal88
Forked from ricardodestro/EXAMPLE_NEO4J.md
Created October 4, 2016 13:03
Show Gist options
  • Save okabasakal88/c1118681ee83ccf406b80dec420e2c35 to your computer and use it in GitHub Desktop.
Save okabasakal88/c1118681ee83ccf406b80dec420e2c35 to your computer and use it in GitHub Desktop.
NEO4J Example

FIAP NEO4J

NEO4J example script

This excercise was created from FIAP - MBA - Solution Architect

#####Create Social Network Node##### CREATE (Facebook:SocialNetwork { name:'Facebook'}) CREATE (Twitter:SocialNetwork { name:'Twitter'})

#####Create Client Node##### CREATE (Ricardo:Client {name:'Ricardo'}) CREATE (Elis:Client {name:'Elis'}) CREATE (Cleber:Client {name:'Cleber'}) CREATE (Fernando:Client {name:'Fernando'})

#####Create Product Node##### CREATE ( Product1:Product {name:'Product1'}) CREATE ( Product2:Product {name:'Product2'}) CREATE ( Product3:Product {name:'Product3'})

#####Create Localization Node##### CREATE (SaoPaulo:Location { name: 'SAOPAULO', state: 'SP', city: 'SAO PAULO' } ) CREATE (RioDeJaneiro:Location { name: 'RIODEJANEIRO', state: 'RJ', city: 'RIO DE JANEIRO' } )

#####Create Opnion Relationship##### CREATE (Ricardo)-[:HAS_OPINION {comment:['comment 1 Facebook']}]->(Facebook), (Elis)-[:HAS_OPINION {comment:['comment facebook 2']}]->(Facebook), (Cleber)-[:HAS_OPINION {comment:['comment twitter 1']}]->(Twitter), (Fernando)-[:HAS_OPINION {comment:['comment twitter 2']}]->(Twitter)

#####Create Location Relationship##### CREATE (Elis)-[:LIVES {zipcode: 1} ]->(SaoPaulo), (Ricardo)-[:LIVES {zipcode: 2} ]->(SaoPaulo), (Cleber)-[:LIVES {zipcode: 3} ]->(RioDeJaneiro), (Fernando)-[:LIVES {zipcode: 4} ]->(RioDeJaneiro)

#####Create buys Relationship##### CREATE (Elis)-[:PURCHASED {qtd: 1, year: '2016', date: '01-01-2016'}]->(Product1), (Elis)-[:PURCHASED {qtd: 2, year: '2016', date: '01-01-2016'}]->(Product2), (Elis)-[:PURCHASED {qtd: 1, year: '2016', date: '01-01-2016'}]->(Product3), (Ricardo)-[:PURCHASED {qtd: 5, year: '2016', date: '01-01-2016'}]->(Product2), (Cleber)-[:PURCHASED {qtd: 1, year: '2016', date: '01-01-2016'}]->(Product3), (Cleber)-[:PURCHASED {qtd: 1, year: '2016', date: '01-01-2016'}]->(Product1), (Fernando)-[:PURCHASED {qtd: 1, year: '2016', date: '01-01-2016'}]->(Product1)

#####Create Seller Node##### CREATE ( Vendor1:Seller {name:'Marco Antonio'}) CREATE ( Vendor2:Seller {name:'Vendor2'})

#####Create clients catalog Relationship##### CREATE (Vendor1)-[:CATALOG]->(Elis), (Vendor1)-[:CATALOG]->(Ricardo), (Vendor2)-[:CATALOG]->(Cleber), (Vendor2)-[:CATALOG]->(Fernando)

#####List all clients's seller with name 'Marco Antonio' that did a buy in 2016 and theses clients are living in Sao Paulo##### MATCH (s:Seller{name:'Marco Antonio'})-[:CATALOG]->(c)-[r:PURCHASED]-(p) WHERE r.year='2016' AND (c)-[:LIVES]-({name: 'SAOPAULO'})
RETURN c,r,p,s

#####Find by name##### MATCH (c {name: "Ricardo"}) RETURN c

#####List of clients##### MATCH (c:Client) RETURN c.name LIMIT 10

#####Delete all database##### MATCH (n) OPTIONAL MATCH (n)-[r]-() WITH n,r LIMIT 50000 DELETE n,r RETURN count(n) as deletedNodesCount

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment