Neo4j Course for Beginners
Key Takeaways
This video course covers the basics of Neo4j, a powerful graph database, and how to use it with Java Spring Boot and React, including setting up a Neo4j database, creating nodes and relationships, and querying the database using Cypher.
Full Transcript
neo4j is a powerful graph database that enables organizations to model store and analyze complex relationships between data points its intuitive graph-based structure offers a flexible and efficient solution for diverse applications making it a leading choice for managing connected data this course is taught by freecocamp team members Farhan choudhary and Gavin long first you will learn about neo4j and graph database Management Systems as well as how you can benefit from incorporating them into your applications next you will learn how to use a neo4j graph database management system as the back-end storage for a real world application created with Java and spring boot finally you will learn how to create a front end with react to interact with the data store with neo4j neo4j provided a grant to make this course possible so let's get started hi and welcome I'm Gavin long so I finally got my free code Camp t-shirt I traveled all the way from the east coast of South Africa to Amsterdam and met the founder of free code Camp Quincy Larson and he gave me my own free code Camp t-shirt really great so the point of the trip was to meet Quincy and some of the core team members of free code camp in person it was about team building and solidifying relationships between co-workers the key Concept in this course is in fact relationships relationships between data the relationships could be between people between car parts between a T-shirt and a human being so relationships between homogeneous data or lack data for example between human beings or relationships between heterogeneous data or different types of data these relationships can be very effectively represented within a graph database management system neo4j is a graph database management system in this part of the course I want to present to you a brief overview highlighting the significance of a graph database management system before we look at neo4j let's contextualize the significance of a graph database management system by looking at some of the other popular types of database Management Systems commonly used today so let's look at three other commonly used types of database Management Systems before we discuss the graph database management system and why we would want to use a graph database management system in our applications the most well-known used database management system type is a relational database management system examples of relational database Management systems are SQL server postgres and MySQL in this type of database tables represent entities for example a table named employee contains rows of data each row of data is divided into columns or Fields containing employee information for example the name field contains the employee name the age field contains the employees age Etc another data entity could be implemented in a table named Department each row in the Department's table denotes an individual department for example one row stores information for the human resources department at another row stores information for the finance department these data entities or database tables within a relational database can be explicitly related to one another within the relational database management system for example an entity may have a one-to-one relationship with another entity so say employees and the cars they drive a specific employee is related to a specific car one employee to one car so for example the employee entity in this case has a one-to-one relationship with the car entity two database tables can have a many-to-many relationship for example an employee could be a member of multiple teams and each team can contain multiple employees so this means an employee can be a member of more than one team and each team can have many employees so in this scenario the employee entity has a many-to-many relationship with the team entity a database entity can have a one-to-many relationship with another database entity for example the department table has a one-to-many relationship with the employee table meaning each department can contain one or many employees and an employee can only be a member of One department at a given time so this one-to-many relationship can be established within the relational database management system through an appropriate schema design a database schema defines how data is organized within a relational database which includes constraints such as table names Fields data types and the relationships between the relevant entities so for example the one-to-many relationship between the department table and the employee table can be implemented by including a primary key which is a unique identifier for a row of data in the department table and a foreign key field within the employee table which relates to the primary key value within the department table the main advantages of a relational database design is that it helps facilitate data Integrity so the data is not easily corrupted as well as reduces data redundancy storage for repeated values are reduced for example if you stored Department data within the employee table you can see here the department short name field and long name field values are repeated across rows in the employee table whereas separating the data into an employee table and a department table means these values are not repeated resulting in Saving storage space as the data scales the storage saving can be quite significant a technique known as normalization is employed to design a relational database I won't go into the details of normalization here but please look up normalization which is a key Concept in relational database design so the technique of normalization can increase data Integrity minimizing data corruption and also significantly reducing data redundancy I.E unnecessarily storing values repeatedly the downside to relational databases is the speed of retrieving data when multiple joins or deep joints between entities are necessary for example if you want to retrieve analytical data that summarizes data from multiple entities a normalized database design can cause the retrieval of such data to be a slow process so way to speed up data retrieval can be to use a schemaless database management system like for example mongodb this is a document-based database management system the fact that the database design is not bound by a schema like with a relational database management system can result in increased speed of data retrieval as well as allow for better design flexibility so you can see that each of these database Management Systems have their purpose and advantages another type of database management system may use a name value pair storage structure like for example redis this database management system is great for caching frequently retrieved data and therefore can help speed up a system so we have briefly looked at three common types of database Management Systems relational database Management Systems like for example SQL server or postgres schema lists database Management Systems like for example mongodb and name value pair database Management Systems like redis so let's look at the significance of a graph database management system neo4j is a graph database management system this type of database management system is based on the graph data structure all of these social media platforms use graph databases Twitter Facebook and Instagram as we all know these platforms have millions of users a relational database management system would not be ideal as the only storage facility for such data because of the way the data is structured would mean multiple joints between entities would need to be made when relevance data is retrieved which would drastically slow down the data retrieval process ultimately causing a poor ux user experience because the whole system is slowed down by these joints that need to be made between data so note that when designing a particular system like a social media platform you could incorporate both a graph database management system and a relational database management system into your overall system design this type of solution could combine the enforced data Integrity inherent and relational database management systems with the complex relationships between data entities or nodes that can be facilitated using a graph database management system for example the master database could be a relational database where data integrity and data redundancy concerns are addressed by the inherent benefits that we have discussed regarding a relational database management system a graph database management system that is appropriately synchronized with the relevant relational database management system can be leveraged to increase the retrieval speed of data that for example has complex relationships if data that requires complex relationships was retrieved directly from the relational database management system the joins required when retrieving the relevance data could significantly slow down the system and ultimately result in a very poor ux user experience so by including a graph database management system in the overall system where it sits on top of the relational database management system as it were and is used to speed up the retrieval of data with complex relationships this could significantly speed up the data retrieval process resulting in a far better ux user experience so this sort of system would require that the data stored in the relevant graph database management system and the relevant relational database management system be synchronized so as to ensure that the data is consistent across the two different database Management Systems so a system like this when designed properly can leverage the benefits of both types of database Management systems for graph-based data structures a database management system that focuses on the facilitation of relationships between entities or nodes is essential and a graph database management system provides a way to store data based on the graph data structure which is ideal for applications that consume data where entities have multiple relationships and complex relationships with one another think about social media platforms where you have relationships between users and posts likes friendships Etc and you have millions of people using these platforms a database management system is needed that appropriately facilitates the storage of data for a large number of different types of relationships a graph database management system allows for relationships to be stored as data within the graph database with a relational database management system the emphasis is on the entities and generally the relationships between the entities are not stored in the database but rather General relationships are established at the design level for example you can see by the foreign key field value that the employee is a member of the HR department but there are no details about the relationship itself between the relevant department and the employee saved in the database this is something you could easily do within a graph database management system you could create a more detailed relationship you can easily save data regarding individual relationships between entities or nodes for example between an employee node and a Department's node so here is a whiteboard presentation that shows how the relationships between individual employees and employees and departments could be represented within a graph database so here we see a node that represents a department this node is appropriately labeled Department details related to this department node can be saved to the database as properties and related values so this department contains a short name property with a value of HR and a long name property with a value of Human Resources here is our first employee node this node is appropriately labeled employee the employee node contains properties and relevant values representing the employee's name and age here we see our first relationship this relationship explicitly shows that the employee whose name is Brad Jenkins is part of the HR department this relationship is appropriately labeled member of so you can see that this is a very human readable representation of data the fact that this employee is a member of the HR department is clear through appropriate labeling and properties so Brad Jenkins is a member of the HR department we are able to add properties to the relationships themselves so the member of relationship has a join date property as well as an employee type property you can see by this data when this employee joined the Department and that this employee has a permanent role and is not for example a contractor here we have the second employee node who has the name Jenny Lane Jenny is also a member of the HR department we can save relationships between employees within our graph database so Jenny works with Brad we can also create another works with relationship in the opposite direction where Brad works with Jenny so you can see that we have a one Department to many employees relationship just like what was shown earlier in the relational database but a graph database is far more flexible in terms of design when establishing relationships between data points or nodes not only can the entities contain Associated data but the relationships themselves can also contain data I.E through properties and Associated values so we could create even more complex relationships between nodes for example a chain of command hierarchical structure related to our employee nodes so here's an example of this where employee James Stokes reports to another employee Jenny Lane this is just a simple example and of course this hierarchical data structure could become far more complex so this presentation was only intended to give you a basic idea of how much more flexible the design of relationships between entities can be within a graph database and how complex relationships between entities can be easily implemented within a graph database I want to show you a brief demonstration of using Cipher to query a graph database and to do this I'll firstly create a neo4j database on my local machine I'll use my Mac platform to demonstrate this I'll contrast using Cipher and neo4j with using SQL in the SQL Server database which of course is a relational database management system firstly what is cipher Cipher can be likened to SQL or structured query language Cipher is a text-based declarative language used for querying a neo4j database what is meant by a declarative language a declarative language is a high-level language that describes what a computation should perform these languages must follow strict semantic rules must be structured in a particular way in order to be valid and for desired results to be returned from the relevance database management system for example using SQL in order to bring back all employee records from the employee table you would appropriately execute the following SQL code the SQL statement simply returns all rows and all columns from the employee table using Cipher if you wanted to return all employee data you would use a query like this this query would return all employee nodes and relevant relationships although When comparing these two query languages they are of course semantically different but principally they are the same and that the relevant declarative text-based code is paused by the appropriate database management system converted into appropriate instructions that are executed under the hood as it were and the relevant results are then returned from the relevant database I'd like to demonstrate using Cipher within a neo4j database I'll contrast executing Cipher against the neo4j database with executing similar queries against a similar database implemented in a SQL Server database you don't need to follow along with this part of the course but of course you can if you want to so if you want to follow along you can install neo4j on your Mac or Windows platforms by following the instructions at this URL I have already installed neo4j on my Mac platform if you want to install a free version of SQL Server please navigate to this URL but as discussed this part of the course is only intended to be an overview and not a detailed explanation so it's not necessary to follow along with this part of the course I've created these scripts on GitHub for this part of the demonstration so I'm going to copy this script from GitHub and run it in neo4j to generate My neo4j Graph database so with the neo4j desktop let's create a new project I'm going to call this project sample project then let's create a new database I'm going to name my neo4j database company DB let's give our database a password then let's press the create button and now we need to start the database so let's press the start button to do this then to execute our Cipher queries let's click this open button and open the appropriate window from which we can execute our Cipher queries so the first thing we need to do is copy the code for creating our graph database so let's navigate to this appropriate GitHub URL let's copy this code from GitHub and appropriately paste the code within the window that we can use to run our queries through neo4j desktop great and let's click the play button to create our graph database excellent and we are presented with appropriate status information telling us that our graph database has been created successfully I'm going to run this script within SQL Server to generate a similar database the difference of course being that this database is designed as a relational database so let's appropriately copy this SQL code from GitHub let's launch SQL Server management Studio let's run our SQL code to create our database I've already created a database named the company DB test so I'm going to create a new database named the company DB test 2. then I need to change the relevant SQL script to point to the new database that I've just created let's press the play button to run the script and create our database tables and relevant data great so I'm going to run a few queries so that you can get a basic understanding of the differences and similarities regarding Cipher and SQL so let's run this query against the neo4j database great this query brings back all the employee nodes and relevant relationships in order to retrieve all employee data from within the relevant SQL Server database you could run a SQL query like this and let's say we wanted to retrieve particular data about a particular employee so you could run this Cipher code like this within the SQL Server database you could run a SQL query like this okay so now the next query I'd like to run is a little bit more interesting so in both these two databases we have expressed a hierarchical relationship between employees in the neo4j database this is implemented through the report 2 relationship established between employees in the SQL Server database the same hierarchical relationship between employees is expressed but through the use of what's known as a self-joining table so in this case the employee table joins to itself through the relationship between the report to ID field and the ID field which stores each employee's ID so in the employee table the hierarchical relationship between employees is established through the use of the reports to ID field which stores the employee ID of the relevant employees immediate boss if you like so employee Brad Jenkins is at the bottom of the hierarchy as it were so if you wanted to query the SQL database to get the chain of command from Brad Jenkins to the top of the hierarchy you need to run a query like this as you can see this query is really difficult to understand at first glance and recursion is used to get the desired results a graph database is far easier to understand in terms of retrieving such tree data structures from the relevance database so to use Cipher code to retrieve the relevant hierarchical data starting with an employee at the bottom of the hierarchy Brad Jenkins you would run Cipher code like this against this particular database great okay so I hope this part of the course has given you at least a basic understanding of a graph database management system and how you can benefit from incorporating a graph database management system into your applications Farhan will now go into more detail where he'll use a neo4j graph database management system as the back-end storage facility for the server-side part of a real-world web-based application I will then follow Farhan and create the front-end code for this application using react hello everyone welcome to this course I am Farhan hassin showed you one of the instructors and I will walk you through the entire process of working with a new 4G database as well as the development of an API powered by Spring boot framework now at this point of the course I will show you how you can create a new account for the neo4j aura Cloud database service how to create a new database and run some simple queries now keep in mind that this is not going to be an exhaustive list of all the commands and queries that you can run inside in your 4J database what I am going to do is I will show you how you can create a node how you can create relationships how you can delete a node update a node and some other basic crowd operations in a word I will teach you whatever is necessary to create the API now to begin with we will navigate to neo4js website I will leave the link in the description so you can follow along and once you are here you will use the get started free button to create a new account now start free and if you wish you can sign up for a new account using your email address but what I am going to do is I will just use my Google account to log in now I have successfully logged into neo4j Aura and I hope you have done that too so this is the dashboard that they give us you can see there are the instances that we are going to create Now to create a new instance of a database just click on the new instance button and it will give you a free templates like if you are a beginner you can start here and it will give you some data to start with what we are going to pick is an empty instance because I want to show you how you can create new nodes relationships labels and things like that so we will hit create then they will generate a password for us now you can copy that password using this button or even better you can use this download button to download all the credentials as a text format now I am not going to do that yet but I will show you later on how that works out so once you have copied the credentials click on confirm I have copied or downloaded the above credentials so that they will know that you have the treatment Shields because you you cannot get it once you have gone past this step now you need to continue now the creation process of a new instance is a bit long it can take around a minute or so so what I'm going to do is I'm going to pause the recording and come back once the instance has been created so it looks like that the database has been created uh it's it's running on gcp or Google Cloud platform and since I am from Asia I am from Bangladesh the region closest to me was Singapore now we also have a connection URI now to connect to this instance all you have to do is click on the open button but before that just in case you want to rename your instance you can go here and you can use rename I am not going to do that though so I will just open it and they will ask for a password so I will just paste in my password and the database user will be neo4j you don't have to change any of these things just click connect now once you have landed on your workspace you will see that there are no notes and relationships whatsoever but I would like to show you how you can create new nodes how you can create new relationships between them how you can update a node now the cipher query language is really expressive and this is really easy to learn if you have experience with some other query languages like SQL but even if you do not have any experience with that Cipher is not that hard to learn the cipher documentation is an excellent piece of resource they also have a cheat sheet now I will leave a link to this cheat sheet in the description of this video you can visit these and you can essentially learn about how to read all the notes in a database using the match clause or how to filter them using where return variables and under write queries you can also learn about creating new nodes levels and relationships set for updating them delete and remove for getting rid of notes and labels and things like that I would suggest that you bookmark this Cipher cheat sheet in your browser so that you can refer back to it whenever you need and also the documentation now I will go back to our workspace and I will start creating a bunch of node and I will explain how you can do that as well so let's switch back to our workspace and the first thing that we want to do is we want to create a new node so we will begin with the create class and a set of parentheses then we will put a colon here and we will write the label of the node so a node is an independent or a single entity inside your database and it has to be labeled something for example if we create a node in our database with the name Farhan has in children it would be hard to say what this node represents does it represent a user does it represent someone's pet cat what is it so we are labeling our node with the label user and then we will put some properties here the first thing I want to put is a name for this user so Farhan Name colon Farhan hasin Chaudhary then I will put a comma the next is a username this is a unique username and we will use it to uniquely identify every single user so we will say username is just farha and that's all I am going to put here now I will execute the command using the play button and looks like we have a new label here and if I click on this it will return everything under this label to us now instead of clicking on this label we can also use the match class so we will say match and we want to match for all the nodes in our database we use a return all the nodes now this is just a variable by the way if you want to call it nodes nodes you can do that as well just make sure you are not using any of the reserved keywords for example if I remove the Acer you will see it becomes red which means it's a keyword like match and return we cannot use it so I will change it back to notes I will run the query and as you can see we have all our nodes here now let's go ahead and create two more users so I will say create and this time I want to actually create multiple users with a single create call so I will keep pressing shift and press enter to come on the next line I will start a set of parentheses I will create a new user with the name John and his username will be just John then outside of the last parenthesis I will put a comma and I will again keep pressing shift and press enter to come to the second line and I will open another set of parentheses I will create another user and her name will be chained and username will be just J it has to be stream now if I end this query with a semicolon at the end I can just press on this play button and as you can see I have successfully created two new nodes at four sets of properties so if I say match in for notes and return in I can get all the nodes in our database so I have foreign I have John and I have Jane now the thing is all these three nodes are of the user level so it would be nice to have another label on our system so let's go ahead and create a bunch of courses Now to create a course we will use the same syntax as before and you can use your up Arrow to bring back your old queries I will just make some changes to this query I will switch user with course in both cases I will replace title we C plus plus course and the username with identity fire this is an unique identifier for the course which is CPP and the next course we will have is title Java Script course and we can call it Js finally we can have another course called C sharp course and its identifier will be C sharp whether I have made a mistake here it should be identifier I'm not username so let's look at our query we are creating three courses with title C plus plus course Java Script codes and C sharp ports they all have uh unique identifier cpp.js and c-sharp so I execute this command uh looks like I have a mistake which is I didn't put a comma at the end and how did I know that so it as you can see neo4j is actually telling me that there is some problem in the beginning of the course title C sharp line but I can see that it's totally fine so it's highly likely that the mistake is actually at the end of the previous line so that's how I thought that maybe I have missed a comma so I will run this query again and I have created three new nodes and I will say match in and I return in so as you can see I have all my notes Here There is Jane John and Farhan has seen jewelry these are the users and C plus plus JavaScript and C sharp these are my courses now it would be nice if I could create a relationship between Jane and this C plus plus course John and JavaScript and foreign C sharp course so I want to essentially enroll them in this course but before that I would like to show you a few variation of the match Clause so right now when we say match in return in it actually returns all the nodes in our database what if I want to only get the course notes or the user nodes we can do that by defining a label after this variable like this so I want all the users return in as users you can actually do that if you use as you can actually rename your variables to make them more user friendly so I am matching all the node of label user and I returning them as users I'll press play as you can see I am now getting only the users and not the courses likewise I can replace n with C or let's just keep it n since that's just a variable I am picking the course as instead of users I will say courses by the way you can press Ctrl enter to execute your query without pressing the play button so right now I am getting only the courses but what if I only want to get one user for example I only want to match for the user with username Farhan so I can do that I can same match you for user so I input user then I will use the where plus this is used for filtering or query results so I would say fire U dot username is equals Farhan return U as far so what I am doing essentially here is I am matching for a user type that has the username Farhan I am putting it inside you and I am returning U as farha let's run this query and as you can see I am getting Farhan has in two three back now let's add a course to the mix so after I am saying U colon user I can put a comma start another set of parentheses I can say C course so where U dot username equals Farhan and C dot identifier is equals CPP so return U comma C but this time I am removing the as pre-word and what I'm doing here I am matching for a user and a course fire the username is equals Farhan and course dot identifier is equals CPP finally I am returning U and C let's see if it works as you can see we have successfully found the C plus plus course and the Farhan has into three users now we are actually ready to create a relationship between these two nodes so I will bring back my old query and instead of returning them I want to say create because I want to create a new relationship and I will first take the user so here I have the user then I will put a dash then a set of square braces and inside I will say colon enrolled in this is the type of relationship this user is going to have with the course so what we are doing we are matching for a user and a course where the username is Farhan and course identifier is CPP then we are creating a relationship what kind of relationship you say we are creating an outgoing relationship from the user and how do I know that as you can see there is an arrow going out from the user towards the course so this is an outgoing relationship from the user and what is the type of this relationship the type is actually enrolled in now we can actually save this relationship inside a variable called r and I can say return r so if I press the play button again yes looks like I have successfully created a relationship so the relationship actually starts at Node 1 and ends at node 4 which means that the ID of Farhan hasin choudhary is 1 and ID of CPP is four if I go to user you can see for Han hassin children has the id1 and if I go to course C plus plus course has the ID of four okay and the type of relationship is enrolled in there are no properties whatsoever there are the element ID start note element idea things like that we do not have to worry about them so that's how you can create a relationship between these two nodes so that's how you can create relationships inside of neo4j now let's see how you can update a property of a node so if I want to update the name of Jane to Jane Doe and John to John Doe I can do that first we have to find John in our database so we will say match a variable U of type user where U dot username equals John so now we are matching for a user with the username John then we want to use set this is another clause in neo4j Cipher language so it's a set U dot name equals John Doe and if I execute this query looks like it has done its job so if I go back and instead of setting it if I return you John has now become John Doe we can do the same thing with Jane because why not they are related Jane and we can say okay so I want to return J return U there you have it so now you have learned how to match nodes in the database you have learned how to create new relationships update values of an existing node now that's pretty much all you are going to need for the API development process but I would like to show you one last Clause from The Cypher query language and that is the exist clause for example if you ever want to check if Farhan hasin tutori is enrolled in the C plus plus course or not you can do that using the exists Clause so we will begin with match and what do we want to match we want to match for an user and we want to match for a course where U dot username sequels Farhan and C dot identifier is equals CPP now we have an user with the username Farhan and we also have a course with identifier CPP next what we want to do is we want to say return and we will call the exists function this is a function and that's why we have these two parentheses and inside this parentheses we want to describe a relationship so the relationship we are looking for or checking for is whether user is enrolled in the course or not okay so you will finish our query what we are doing we are matching for a user with the username Farhan and we are matching for a course with the identifier CPP then you are checking whether a relationship between them of type enrolled in exists or not so I'll press the play button and it says true now if I switch CPP for something else like JS we have the JavaScript course and I hit the play button you will see I am getting false now to be honest that's all you need to know to go through this entire course but Cipher is really excellent query language and if you have plans to learn a lot more neo4j than I have showed you in this course I would suggest that you go through the documentation you go through their cheat sheet and you practice making your own databases creating them in a lot of different scenarios and learn as much as you can about this database system now I am going to finish this lesson here but in the next lesson you will see me using an initializer Cipher script to create a new database for our API and from there we will begin working on our Java code in this part of the course we are finally going to start working on our spring boot API but before that we need to set a few things up first thing first go back to your neo4j aura database dashboard and delete any old instances that you may have created while working with the API we want to start with a clean slate so that we can be sure of the fact that some old data will not mess up our API to delete an old instance you can use the delete button here and then you will have to write the name of the instance it's just to make sure that you are in your right senses and you are not sleeping or anything click on the destroy button and wait until the instance is being destroyed Now to create a new instance use the new instance button choose empty instance and click on the create button make sure you download the credentials file because we are going to need it later on and also let them know that you have downloaded the credential file by clicking on this checkbox click on continue now creating a new instance may take a few minutes so what I'm going to do is I'm just going to speed up the process in this video so that you don't have to wait around for long once the instance has been created click the open Button accept their terms and conditions and when they ask for the password open up the credentials file you just downloaded just highlight the password Here copy it and paste it on the empty password field click on connect and we have successfully connected to our new instance now as you can see this instance is completely empty but we will need some data to work on our API for that I have already created an initializer script that you can use to initialize the database for that go to the code repository on GitHub I will leave the link on the descriptions below then go inside the data folder you will find a file called initializer.cipher open up this file and go to Raw highlight all the lines and copy with Ctrl C then go back to your aura DB dashboard paste the code that you just copied and then press the play button to execute the code as you can see the code has successfully created some notes relationships and property keys now the first note that I would like to show you is the user node now this represents all the users in our database for example if we open up John Price you can see that it has an ID it has a name John price it has an encrypted password hash it has roles and it has username now the significance of each of these properties will become more clear as you start working on the API but for now just keep in mind that all these properties are important for our application next up we have course a this represent each of the courses that will be available on our system so if I click on the Blazer shopping cart course you can see that it has an ID of pen it has a string identifier that we are going to use to uniquely identify this course it has the name of the teacher and a title now you may argue that we can use the ID to uniquely identify this course while that's correct I prefer using some other unique string or identifier to identify my course or entities I just do not like to rely on the auto generated ID fields in any database at all finally we have the lessons these are the individual lessons that belongs to some course for example if we click on the Blazer webassembly and web API on dotnet 6. listen you can see it has an identifier just like the courses it has a title and it also has an ID now these lessons here has a belongs to relationship with the courses which means each of these lessons belongs to a certain course for example if I zoom in on the Blazer course as you can see all these four lessons belongs to the Blazer shopping cart course finally there is the enrolled in relationship which is between the individual users and courses so for example John W here is enrolled in the Blazer shopping cart course now that we are done with our database we can finally start working with our API for that you will need jdk pre-installed on your computer now you can download the jdk from oracle's website I am going to use jdk 17 since that's the latest long term support release but you can also go with jdk 20 it's totally up to you one more thing for those who are watching this course on Linux it's totally fine to use any of the open jdk builds for example I myself am using the Microsoft build of open jdk instead of oracle's official build and given the complexity of our API it's not going to make any change or it it will not break anything whatsoever so feel free to use uh any open jdk build that you like you will also need a good ide to make your you know programming process more fun I'm going to use IntelliJ IDEA ultimate here I have a student license so I'm going to use that but if you want you can also use the Community Edition to be honest if you look at the feature comparison here most of the essentials are available under the Community Edition we do not need the HTTP client thing since we are going to use a third party client anyway we do not need database tools or SQL or any of these things for this project at least finally we need to initialize our project for that we are of course going to use the spring initializer now I will leave the link to Spring initializer down in the description so once you have navigated to this page we will make some choices here and we will generate our project boilerplate first make sure that you are picking Maven under project here you can also use griddle if you have previous experience with the tool but I am just going to pick maven the language will remain Java for the spring boot version I am going to use 3.1.0 since that's the latest at the time of recording but if some other version comes out later on while you are watching this course feel free to use that just do not pick any of the snapshots you can stable release now under group you will have to type or you should type some domain in reverse order for example my own domain is farhan.dev so I will just type in Dev Dot then artifact is just a project name so I am going to call it spring boot neo4j you may call it anything that you like I will also put a sensible description like a simple API powered by you know or Che finally make sure that you are picking the correct Java version from down here I am going to pick 17 since that's what I have installed on my computer but if you have installed 20 make sure that you're switching to 20. for packaging format we will go with jar since that a lot widely used than wire format so let's not change that another most important part adding dependencies now this is needless to say that we will need a number of different dependencies for our project but for starters I will just pick spring web and the devtools now you may think that Why not pick the new 4G dependencies while we are here well I could have picked them but one thing that I have noticed in the past is that many people face difficulties while they try to add new dependencies to a project that they have already initialized so I thought why not to start the project with just the bare bones uh you know essential dependencies only and then as we go forward we will keep adding new dependencies to our project that way it will represent a much more realistic you know development workflow and it will also teach you how you can search for new dependencies and add them on the flag so take a good look at all the choices you have made and once you are happy with them click on generate it will download a little zip file to your computer that contains all the project 5. I'm going to just open up the zip file using no Windows Explorer or WinRAR or whatever you like copy the project folder go to a place that where you usually put your codes in I usually put them in individual directories so I'm going to paste it here and once I have done that I will just open up my IDE which is IntelliJ IDEA I will open up my project input neo4j okay yes we trust the project and once you have opened the project for first time I would say give it some time to you know cash all your dependencies uh read the source files and things like that so the ID knows about your project and it can help you along the way hello everyone I am your instructor Farhan but I am from future now in the next lessons you may see a little problem with the video in some cases when I am trying to create a new class or maybe a new package you may see that this menu is not showing up now this is because my recorder was only recording one window in my computer so all this sub menus were invisible so whenever you see me creating a new package all you have to do is right click on your main package go to new and then package likewise when I am cheating in new class you have to pick Java class from here and you can switch between interfaces and classes right from this menu another thing that didn't work in my previous recording was the code generation thing so whenever you are creating a new model you can use the alt insert key combination sorry inside the class of course let's get rid of the Constructor and you can use alt insert and you can then generate a Constructor you can generate Getters and Setters and equals and hash code two strings and all those boilerplate methods so what I did in those videos is I picked Constructor and then I just ignored all these properties since you are trying to create an empty Constructor and then press ok so a good chunk of the course if you see all these sub menus are invisible just don't be alarmed it was some problem with my recorder everything should work as is in your computer now back to the past as you can see IntelliJ IDEA has finally finished resolving all the dependencies in my project so I am finally ready to write some code now before we start writing Java code I'd like to address something really important I hope that you remember back when we are generating our project we didn't add all the dependencies to our project because I wanted to show you how you can manually add dependencies later on so this is the time we do that first open up your pom.xml and find this dependencies part inside that you can see that there are three dependencies already described you may recognize the spring boot starter web and springboard Dev tools dependencies from a few moments ago when we added them to our project but there is also another thing called Spring boot a startup test now this is for testing our code and in this course we are not going to talk about that now the first dependency that we need to add to our project is called the spring put a starter data neo4j and the group ID will be org Dot springframework.put now IntelliJ IDEA is being really generous here and helping us out with writing the dependencies but I suggest that you make sure that you are typing them out correctly because if you make a typo or write wrong name then you may end up not getting a dependency or even worse getting the wrong dependency now the second dependency that we need is called the neo4j Java driver and the group is org.neo4j dot driver now whenever you add or remove a dependency from your palm.xml file you have to right click on the palm.xml file find Maven and reload project depending on how many dependencies you have added or removed from your project the resolving process may take a while but in my case it has finished in a Flash now I will close the pom.xml file and start creating the packages that we will need now inside our main package dave.farhand.springboot neo4j it may be something else in your case but inside our main package we will create four new packages now the first one will be called config then we will create another package called models then we will have the repositories then we will have the services and our controllers now these are not the only packages that we are going to need we will also need some packages to hold our query results our data transfer objects our requests and things like that but we'll work on them later for now these are the ones that we need now once you have all the package ready to go let's create the model for our first node which in this case will be the course so let's create a new Java class and call it course then inside we will Define all the necessary properties of this class so the first one is an ID and it has to be of type long then we will have private string identifier which will used uniquely identify our courses then private string title and private extreme teacher then we will create a Constructor now you may write the Constructor by hand but inside IntelliJ you can just press on alt and then insert to bring up this nice generate menu from here you can select Constructor and for our Constructor we will not select any of the properties now for spring data neo4j this is one of the requirements that you create an empty Constructor inside your model classes so this is what we are going to do then we will say alt insert and we will select Getters and setters highlight identifier title and teacher we will not highlight ID and why you will understand in a bit click OK and now we have all the Getters and Setters for our private properties now creating a class like this will not suffice who you will also have to annotate this class with the node annotation This Way Spring boot will know that this class is actually a new 4G node and has to be managed by the dependency injection system then inside the class we will also annotate the ID with two separate annotations the first one has to be the ID annotation to let springboot know that this is the ID for the node and then we will say generated value which means we want this value to be automatically generated and we do not want to write it by hand now since this ID is an automatically generated value we do not need a set of file and since we are not going to use these two uniquely identify our course
Original Description
Learn how to use Neo4j with Java Spring Boot and React. Neo4j is a powerful graph database that enables organizations to model, store, and analyze complex relationships between data points. It's intuitive graph-based structure offers a flexible and efficient solution for diverse applications, making it a leading choice for managing connected data.
This course is taught by freeCodeCamp team members Farhan Chowdhury and Gavin Lon.
🏗 Neo4j provided a grant to make this course possible.
⭐️ Important Links ⭐️
🔗 Neo4j - https://neo4j.com/
💻 Spring Boot Project Code - https://github.com/fhsinchy/spring-neo4j
💻 React Code - https://github.com/GavinLonDigital/Curriculum-mngt
🔗 Oracle Java Development Kit - https://www.oracle.com/java/technologies/downloads/
🔗 Microsoft Build of OpenJDK - https://www.microsoft.com/openjdk
🔗 IntelliJ IDEA - https://www.jetbrains.com/idea/
🔗 Cypher Cheat Sheet - https://neo4j.com/docs/cypher-cheat-sheet/
🔗 Cypher Docs - https://neo4j.com/docs/cypher-manual/current/introduction/
🔗 Field Dependency Injection Considered Harmful - https://www.vojtechruzicka.com/field-dependency-injection-considered-harmful/
❤️ Try interactive Databases courses we love, right in your browser: https://scrimba.com/freeCodeCamp-Databases (Made possible by a grant from our friends at Scrimba)
⭐️ Contents ⭐️
0:00:00 Introduction
0:02:38 Discussion on Commonly Used Database Management Systems
0:08:00 Social Media Platforms and Graph Database Management Systems
0:08:49 The Integration of a Graph Database Management System into an Overall System Design
0:11:10 Relationships in RDBMS vs. Relationships in GDBMS
0:11:55 Whiteboard Presentation Highlighting Relationships between Nodes in. GDBMS
0:14:59 Discussion on SQL and Cypher
0:17:03 Install Neo4j Desktop
0:17:15 Install SQL Server
0:17:35 Create Graph Database and Similar SQL Server Database
0:20:40 Run Cypher Queries and Similar SQL Queries
0:24:58 Creating database and connecting to database
0:28:46 P
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from freeCodeCamp.org · freeCodeCamp.org · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
React: Production Server Setup Part 2 - Live Coding with Jesse
freeCodeCamp.org
cookies vs localStorage vs sessionStorage - Beau teaches JavaScript
freeCodeCamp.org
Browser history tutorial - Beau teaches JavaScript
freeCodeCamp.org
Graph Data Structure Intro (inc. adjacency list, adjacency matrix, incidence matrix)
freeCodeCamp.org
React: Parameterized Routing with Next.js - Live Coding with Jesse
freeCodeCamp.org
React: Dealing with jQuery Issues - Live Coding with Jesse
freeCodeCamp.org
setInterval and setTimeout: timing events - Beau teaches JavaScript
freeCodeCamp.org
Browser and Device Testing - Live Coding with Jesse
freeCodeCamp.org
Last Minute Updates - Live Coding with Jesse
freeCodeCamp.org
Post Launch Updates - Live Coding with Jesse
freeCodeCamp.org
React: Setting Up Google Analytics - Live Coding with Jesse
freeCodeCamp.org
React: Masonry Layout - Live Coding with Jesse
freeCodeCamp.org
Load Balancing Digital Ocean Droplets - Live Coding with Jesse
freeCodeCamp.org
try, catch, finally, throw - error handling in JavaScript
freeCodeCamp.org
Load Balancing: SSL Passthrough Setup - Live Coding with Jesse
freeCodeCamp.org
Graphs: breadth-first search - Beau teaches JavaScript
freeCodeCamp.org
React: Masonry Layout Part 2 - Live Coding with Jesse
freeCodeCamp.org
React: WordPress API Live Search - Live Coding with Jesse
freeCodeCamp.org
Creating WordPress Custom Post Types - Live Coding With Jesse
freeCodeCamp.org
Dates - Beau teaches JavaScript
freeCodeCamp.org
Miscellaneous Front End Updates - Live Coding with Jesse
freeCodeCamp.org
Merging a Pull Request from GitHub - Live Coding with Jesse
freeCodeCamp.org
React + Prettier + Standard JS - Live Coding with Jesse
freeCodeCamp.org
React: Sortable Responsive Table - Live Coding with Jesse
freeCodeCamp.org
Geolocation Sorting by Distance - Live Coding with Jesse
freeCodeCamp.org
Tradeoff Matrix - Agile Software Development
freeCodeCamp.org
The Definition of Ready - Agile Software Development
freeCodeCamp.org
Getting first React job without experience - Ask Preethi
freeCodeCamp.org
React: Google Analytics Click Tracking - Live Coding with Jesse
freeCodeCamp.org
Submitting a PR to an Open Source Project - Live Coding with Jesse
freeCodeCamp.org
Should I go back to school to get CS degree? - Ask Preethi
freeCodeCamp.org
Hero Section CSS Changes - Live Coding with Jesse
freeCodeCamp.org
Working Agreement - Agile Software Development
freeCodeCamp.org
A day at Pennybox with Co-Founder Reji Eapen
freeCodeCamp.org
React: Sorting and Filtering Data - Live Coding with Jesse
freeCodeCamp.org
React: Sorting and Filtering Data Part 2 - Live Coding with Jesse
freeCodeCamp.org
React: Building a New UI - Live Coding with Jesse
freeCodeCamp.org
Definition of Done - Agile Software Development
freeCodeCamp.org
Getting started with jQuery (tutorial) - Beau teaches JavaScript
freeCodeCamp.org
Making a React Blog with WordPress Content - Live Coding with Jesse
freeCodeCamp.org
React, NextJS, CSS - Live Coding with Jesse
freeCodeCamp.org
jQuery events - Beau teaches JavaScript
freeCodeCamp.org
React/NextJS Routing and WordPress API Custom Types - Live Coding with Jesse
freeCodeCamp.org
React: Working with API Data - Live Coding with Jesse
freeCodeCamp.org
React: Refactoring Components - Live Streaming with Jesse
freeCodeCamp.org
jQuery effects - Beau teaches JavaScript
freeCodeCamp.org
More React Refactoring - Live Coding with Jesse
freeCodeCamp.org
animate in jQuery - Beau teaches JavaScript
freeCodeCamp.org
"Finishing" My React Site - Live Coding with Jesse
freeCodeCamp.org
Starting a New React Project (P2D1) - Live Coding with Jesse
freeCodeCamp.org
React Project 2 Day 2: Learning Material UI - Live Coding with Jesse
freeCodeCamp.org
The Agile Manifesto - Agile Software Development
freeCodeCamp.org
jQuery: get and set with http, text, val, and attr - Beau teaches JavaScript
freeCodeCamp.org
React Project 2 Day 3 - Live Coding with Jesse
freeCodeCamp.org
The INVEST approach to product backlog items
freeCodeCamp.org
React Project 2 Day 4 - Live Coding with Jesse
freeCodeCamp.org
Chickens and Pigs - Agile Software Development
freeCodeCamp.org
React Project 2 Day 5 - Live Coding with Jesse
freeCodeCamp.org
jQuery: add and remove DOM elements - Beau teaches JavaScript
freeCodeCamp.org
React Project 2 Day 6 - Live Coding with Jesse
freeCodeCamp.org
More on: LLM Foundations
View skill →Related Reads
📰
📰
📰
📰
The Data Scientist Role Isn’t Dead. But the Old Version of It Is.
Medium · Machine Learning
The Data Scientist Role Isn’t Dead. But the Old Version of It Is.
Medium · Data Science
Boosting Startups with Data Science: A Practical Guide to Data-Driven Growth
Medium · Startup
One Lake, Five Patterns: Rethinking the Enterprise Data Foundation
Medium · Data Science
Chapters (12)
Introduction
2:38
Discussion on Commonly Used Database Management Systems
8:00
Social Media Platforms and Graph Database Management Systems
8:49
The Integration of a Graph Database Management System into an Overall System Des
11:10
Relationships in RDBMS vs. Relationships in GDBMS
11:55
Whiteboard Presentation Highlighting Relationships between Nodes in. GDBMS
14:59
Discussion on SQL and Cypher
17:03
Install Neo4j Desktop
17:15
Install SQL Server
17:35
Create Graph Database and Similar SQL Server Database
20:40
Run Cypher Queries and Similar SQL Queries
24:58
Creating database and connecting to database
🎓
Tutor Explanation
DeepCamp AI