Course Nodes

Adding Multiple Nodes in Neo4j

Following in the steps of Max De Marzi of Neo4j, I thought I’d document some of my own issues in trying to work with Neo4j.  I had the privelege of meeting Max at a Neo4j Graph Days event in Chicago, and he talked about how he used his blog as a notebook/wiki for documenting some of the things he had learned in developing with Neo4j.  I’m starting here at the very beginning of a project as someone who has more of a grasp on Neo4j than the average bear, but I’m still struggling.  After taking about 90 minutes to figure out how to import 500+ nodes with properties from a spreadsheet, I thought I ought to document this process so I wouldn’t have to look so hard in the future.

I was trying to work from this documentation.  I’m going to assume there’s something about using parameters that I’m not aware of, as I couldn’t get anything like this to work.  When I get that understanding, I’ll add that documentation here too.

I’m working on an application for college students.  Say you’re about to start your senior year of college, and maybe you know you need one or two more required classes for your major, but you need other classes too.  I’m trying to create a recommendation engine that will look at all of your credits, and tell you if you’re a few classes away from another minor or major.  I hope to build in course rotations so you can find out if those classes are being offered in the upcoming semesters.

So I had a spreadsheet of all the course numbers and titles, and I wanted to create nodes for them all at one time since there were over 500 courses.  I found my solution in this video (go to around one minute, column D).  Instead of just using a letter for a node, I used a index with the letter, so my final code looked something like this.

Create (p1:program { name:'Fine and Performing Arts'}),
(p2:program { name:'Business, Law, and Technology'}),
(p3:program { name:'Communication'}),
(p4:program { name:'Education'}),
(p5:program { name:'Equestrian Studies'}),
(p6:program { name:'Humanities'}),
(p7:program { name:'Professional Studies'}),
(p8:program { name:'Science'}),
(p9:program { name:'Sports Studies'})

Using this method, I was able to very quickly add nine nodes with properties.  Something very similar was done for the 500+ courses at our university.