{"id":6112,"date":"2018-12-07T18:32:40","date_gmt":"2018-12-07T18:32:40","guid":{"rendered":"https:\/\/blog-stg.cheesecakelabs.com\/blog\/starting-graph-databases-quick-look-neo4j\/"},"modified":"2022-07-01T17:22:52","modified_gmt":"2022-07-01T17:22:52","slug":"starting-graph-databases-quick-look-neo4j","status":"publish","type":"post","link":"https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/","title":{"rendered":"Starting with Graph Databases: A Quick look into Neo4j"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Let\u2019s talk about Neo4j, a graph database that recently has attracted a significant number of fans. My goal is for you to have a brief (I promise to be quick) vision of how it works and to give you some examples to make it more tangible.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We are used to write data using tables, to relate them through primary keys and, by looking directly at the data, you only see IDs. Graph databases were designed mainly so that this doesn&#8217;t happen. Its purpose is for you to have a complete understanding when looking at the data.<\/span><!--more--><\/p>\n<figure id=\"attachment_6106\" aria-describedby=\"caption-attachment-6106\" style=\"width: 700px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"size-full wp-image-6106\" src=\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2018\/12\/natam-post1.png\" alt=\"\" width=\"700\" height=\"450\"><figcaption id=\"caption-attachment-6106\" class=\"wp-caption-text\">Example of a simple school database diagram.<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">First of all, to understand an advantage of graph databases, it&#8217;s very good to know a few concepts that reinforce the idea of software close to the business rules. For that, it is worth reading <\/span><a href=\"https:\/\/en.wikipedia.org\/wiki\/Domain-driven_design\"><span style=\"font-weight: 400;\">Domain-Driven Design<\/span><\/a><span style=\"font-weight: 400;\">, where the model should be as close as possible to the business. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">In Neo4j, that is done with Cypher: a declarative SQL-inspired language for describing patterns in visual graphs using an ASCII syntax. It allows us to state what we want to select, insert, update or delete from our graph data without requiring us to describe exactly how to do it.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To be more practical, mind the example below, where the same &#8220;query&#8221; is implemented with SQL and Cypher.<\/span><\/p>\n<pre class=\"language-sql\" style=\"font-size: 20px;\"><code class=\"language-sql\">SELECT f.* FROM students s\nINNER JOIN person p\nON p.id = s.person_id\nINNER JOIN friend f\nON f.friend_from_id = p.id\nWHERE s.id = 45\nORDER BY p.name<\/code><\/pre>\n<pre class=\"language-sql\" style=\"font-size: 20px;\"><code class=\"language-sql\">MATCH\n(student :Student)-[FRIEND]-&amp;gt;(person :Person)\nWHERE student.id = 45\nRETURN person\nORDER BY person.name<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">Above there&#8217;s a &#8220;query&#8221; to search for a specific student&#8217;s friends, where in the traditional mode (SQL) we need to better understand the database structure and know how they relate, causing a greater use of &#8220;JOINS&#8221;. In Cypher relations are more intuitive for reading.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Graph databases are a more natural way of storing the data. You don&#8217;t have to worry about tables and foreign keys and it keeps everything within two simple concepts: nodes and relations. Each node or relation can have its attributes and labels of identification, a way to categorize the data.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To make it easier to understand, let\u2019s map a school in a simple way, where we have students, teachers and courses. How would a diagram represent this? Would you do it in a graph database? It is actually simpler than you think! Just draw it:<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-6109\" src=\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2018\/12\/natam-post4.png\" alt=\"\" width=\"700\" height=\"450\"><\/p>\n<p><span style=\"font-weight: 400;\">Now, hands-on! <\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">You can <\/span><a href=\"https:\/\/neo4j.com\/download\/\"><span style=\"font-weight: 400;\">install Neo4j on your computer<\/span><\/a><span style=\"font-weight: 400;\"> or do it using Docker:<\/span><\/p>\n<pre class=\"language-yaml\"><code class=\"language-yaml\">image: neo4j:3.4.5\nports:\n  - \"7474:7474\"\n  - \"7473:7473\"\n  - \"7687:7687\"\n<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">Don&#8217;t forget to follow the <a href=\"https:\/\/neo4j.com\/docs\/developer-manual\/current\/cypher\/syntax\/naming\/\">rules and nomenclature recommendations<\/a>.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Creating our first nodes:<\/span><\/p>\n<pre class=\"language-sql\"><code class=\"language-sql\">CREATE (s)-[k:KNOWS]-&gt;(t), (t)-[ts:TEACHES]-&gt;(c), (s)-[e:ENROLLED]-&gt;(c)\nCREATE (user1:Person:Student { name: \"Natam\" })\nCREATE (user2:Person:Teacher { name: \"Natalia\" })\nCREATE (course:Course { title: \u201cMath\u201d })<\/code><\/pre>\n<p><em><span style=\"font-weight: 400;\">Now let\u2019s relate them:<\/span><\/em><\/p>\n<pre class=\"language-sql\"><code class=\"language-sql\">MATCH (s:Student {name:\"Natam\"}), (t:Teacher {name:\"Natalia\"}), (c:Course {title:\"Math\"})<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">Now that we have our data, we need to consult it. Let\u2019s do this?<\/span><\/p>\n<pre class=\"language-sql\"><code class=\"language-sql\">MATCH (n) RETURN n<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">This command will return an overview of your graph. You can apply more filters and conditions to your &#8220;query&#8221;. Check this out: <\/span><a href=\"https:\/\/medium.com\/r\/?url=https%3A%2F%2Fneo4j.com%2Fdocs%2Fdeveloper-manual%2Fcurrent%2Fcypher%2Fclauses%2Fwhere%2F\"><span style=\"font-weight: 400;\">https:\/\/neo4j.com\/docs\/developer-manual\/current\/cypher\/clauses\/where\/<\/span><\/a><\/p>\n<h1><b>Conclusion, but already?<\/b><\/h1>\n<p><span style=\"font-weight: 400;\">Yes! The purpose of this post is for you to get to know this incredible technology and how basic is its structure. If you found it interesting and want to learn more about it, try modeling applications you already know using Neo4j. I\u2019m sure you\u2019ll be even more surprised!<\/span><\/p>\n<p><span style=\"font-weight: 400;\">I will leave a few links in case you want to know more concepts related to this technology.<\/span><\/p>\n<h3>REFERENCES<\/h3>\n<p><a href=\"https:\/\/medium.com\/r\/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FSemantic_Web\"><span style=\"font-weight: 400;\">Semantic Web &#8211; Wikipedia<\/span><\/a><\/p>\n<p><a href=\"https:\/\/medium.com\/r\/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FSemantic_Web\"><span style=\"font-weight: 400;\">The Semantic Web is an extension of the World Wide Web through standards by the World Wide Web Consortium (W3C). The\u2026<\/span><span style=\"font-weight: 400;\">en.wikipedia.org<\/span><\/a><\/p>\n<p><a href=\"https:\/\/medium.com\/r\/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FOntology\"><span style=\"font-weight: 400;\">Ontology &#8211; Wikipedia<\/span><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let\u2019s talk about Neo4j, a graph database that recently has attracted a significant number of fans. My goal is for you to have a brief (I promise to be quick) vision of how it works and to give you some examples to make it more tangible. We are used to write data using tables, to [&hellip;]<\/p>\n","protected":false},"author":65,"featured_media":9378,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1163],"tags":[],"class_list":["post-6112","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-process-br"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Starting with Graph Databases: A Quick look into Neo4j | Cheesecake Labs<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Starting with Graph Databases: A Quick look into Neo4j | Cheesecake Labs\" \/>\n<meta property=\"og:description\" content=\"Let\u2019s talk about Neo4j, a graph database that recently has attracted a significant number of fans. My goal is for you to have a brief (I promise to be quick) vision of how it works and to give you some examples to make it more tangible. We are used to write data using tables, to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/\" \/>\n<meta property=\"og:site_name\" content=\"Cheesecake Labs\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cheesecakelabs\" \/>\n<meta property=\"article:published_time\" content=\"2018-12-07T18:32:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-01T17:22:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2018\/12\/artepostNatam.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2000\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Cheesecake Labs\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cheesecakelabs\" \/>\n<meta name=\"twitter:site\" content=\"@cheesecakelabs\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. tempo de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/\",\"url\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/\",\"name\":\"Starting with Graph Databases: A Quick look into Neo4j | Cheesecake Labs\",\"isPartOf\":{\"@id\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/#website\"},\"datePublished\":\"2018-12-07T18:32:40+00:00\",\"dateModified\":\"2022-07-01T17:22:52+00:00\",\"author\":{\"@type\":\"person\",\"name\":\"Natam Oliveira\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Starting with Graph Databases: A Quick look into Neo4j\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/#website\",\"url\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/\",\"name\":\"Cheesecake Labs\",\"description\":\"Empresa de desenvolvimento e design de aplicativos mobile &amp; web que est\u00e1 reinventando o desenvolvimento de produtos com times remotos. N\u00f3s desenvolvemos aplicativos iOS, Android e aplica\u00e7\u00f5es Web com as melhores empresas dos EUA, do Brasil e do mundo.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"Person\",\"name\":\"Natam Oliveira\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/#\/schema\/person\/image\/\",\"url\":false,\"contentUrl\":false,\"caption\":\"Natam Oliveira\"},\"description\":\"10 years of experience in Marketing and Sales in the Technology sector. My main purpose is help, support and structure efficient operations and also develop independent and multidisciplinary teams.\",\"url\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/\/autor\/\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Starting with Graph Databases: A Quick look into Neo4j | Cheesecake Labs","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"pt_BR","og_type":"article","og_title":"Starting with Graph Databases: A Quick look into Neo4j | Cheesecake Labs","og_description":"Let\u2019s talk about Neo4j, a graph database that recently has attracted a significant number of fans. My goal is for you to have a brief (I promise to be quick) vision of how it works and to give you some examples to make it more tangible. We are used to write data using tables, to [&hellip;]","og_url":"https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/","og_site_name":"Cheesecake Labs","article_publisher":"https:\/\/www.facebook.com\/cheesecakelabs","article_published_time":"2018-12-07T18:32:40+00:00","article_modified_time":"2022-07-01T17:22:52+00:00","og_image":[{"width":2000,"height":720,"url":"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2018\/12\/artepostNatam.png","type":"image\/png"}],"author":"Cheesecake Labs","twitter_card":"summary_large_image","twitter_creator":"@cheesecakelabs","twitter_site":"@cheesecakelabs","twitter_misc":{"Escrito por":null,"Est. tempo de leitura":"3 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/","url":"https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/","name":"Starting with Graph Databases: A Quick look into Neo4j | Cheesecake Labs","isPartOf":{"@id":"https:\/\/blog-stg.cheesecakelabs.com\/br\/#website"},"datePublished":"2018-12-07T18:32:40+00:00","dateModified":"2022-07-01T17:22:52+00:00","author":{"@type":"person","name":"Natam Oliveira"},"breadcrumb":{"@id":"https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog-stg.cheesecakelabs.com\/br\/starting-graph-databases-quick-look-neo4j\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog-stg.cheesecakelabs.com\/br\/"},{"@type":"ListItem","position":2,"name":"Starting with Graph Databases: A Quick look into Neo4j"}]},{"@type":"WebSite","@id":"https:\/\/blog-stg.cheesecakelabs.com\/br\/#website","url":"https:\/\/blog-stg.cheesecakelabs.com\/br\/","name":"Cheesecake Labs","description":"Empresa de desenvolvimento e design de aplicativos mobile &amp; web que est\u00e1 reinventando o desenvolvimento de produtos com times remotos. N\u00f3s desenvolvemos aplicativos iOS, Android e aplica\u00e7\u00f5es Web com as melhores empresas dos EUA, do Brasil e do mundo.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog-stg.cheesecakelabs.com\/br\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-BR"},{"@type":"Person","name":"Natam Oliveira","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/blog-stg.cheesecakelabs.com\/br\/#\/schema\/person\/image\/","url":false,"contentUrl":false,"caption":"Natam Oliveira"},"description":"10 years of experience in Marketing and Sales in the Technology sector. My main purpose is help, support and structure efficient operations and also develop independent and multidisciplinary teams.","url":"https:\/\/blog-stg.cheesecakelabs.com\/br\/\/autor\/\/"}]}},"_links":{"self":[{"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/posts\/6112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/comments?post=6112"}],"version-history":[{"count":1,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/posts\/6112\/revisions"}],"predecessor-version":[{"id":10229,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/posts\/6112\/revisions\/10229"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/media\/9378"}],"wp:attachment":[{"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/media?parent=6112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/categories?post=6112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/tags?post=6112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}