Noob question about how complete does the model need to be to fully use neo4jrb

87 views
Skip to first unread message

John Clegg

unread,
Oct 13, 2014, 5:21:01 PM10/13/14
to neo...@googlegroups.com
Hi

I'm migrating from neography to neo4jrb. I'm trying to test neo4jrb with my data structure and I've struck some problems. I have 4 nodes and 4 relationships in  my dataset. 

My question is do I need to define all of the nodes and their relationships from my dataset within the model to use neo4jrb properly?

I created a model with a Node class with just the properties of a single node (with none of the relationships). I wanted to test that it was working, so I tried to query an item from that node structure, I got a "[]" empty result from the .all function.

The equivalent from the movie example would be (which I haven't tested is)

class Movie
include Neo4j::ActiveNode
id_property :title
property :released
property :tagline


end


I was hoping that I could prove that neo4jrb worked without migrating all the nodes and relationships . Once I proved that it worked I am planning to migrate all the data structures. 

Just to confirm, I have run the ruby code with the movie example and that works. And I have tested raw queries with neo4j-core, so I know that the Neo4j DB is up and accepting requests. 

Thanks

John

Brian Underwood

unread,
Oct 13, 2014, 5:30:11 PM10/13/14
to neo...@googlegroups.com
The problem is that the neo4j REST API before 2.1.5 didn't send us labels, so we made a _classname property which stored the name of the model class so that we could the right model.  Starting with 2.1.5 the API sends labels and we plan on supporting that.

For now you should try setting the _classname property of your nodes to be the same as the label / class model you want to load.  Something like.

MATCH (u:User) SET u._classname = "User"

And you don't need to create model classes for all of your nodes/relationships, just the ones you care about working with via the gem.

Brian
;p


--
You received this message because you are subscribed to the Google Groups "neo4jrb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4jrb+u...@googlegroups.com.
To post to this group, send email to neo...@googlegroups.com.
Visit this group at http://groups.google.com/group/neo4jrb.
For more options, visit https://groups.google.com/d/optout.

Brian Underwood

unread,
Oct 13, 2014, 6:08:16 PM10/13/14
to neo...@googlegroups.com
I just remembered that you'll also need to add UUIDs which we now require.  The best way to add those as well as the _classname is via our built in migrations:


Brian
;p


John Clegg

unread,
Oct 13, 2014, 7:21:27 PM10/13/14
to neo...@googlegroups.com
Thanks Brian,

I didn't say which version of neo4j server I'm using - Neo4j 2.1.2 because of the spatial plugin.  (BTW It would be awesome if neo4jrb supported the spatial plugin.)

I'll set the class_name and I'll read the documentation around migration. 

Cheers

John

John Clegg

unread,
Oct 14, 2014, 4:56:32 AM10/14/14
to neo...@googlegroups.com
Hi Brian,

I've add the _classname via the query.

I'm now getting a rake error when I try to add the UUIDs.

# rake neo4j:migrate[add_id_property,setup]

rake aborted!

LoadError: cannot load such file -- neo4j/tasks/migration.rake

The rake file contains.

load 'neo4j/tasks/migration.rake'

John


Andreas Ronge

unread,
Oct 14, 2014, 5:58:48 AM10/14/14
to neo...@googlegroups.com
Check this example, which does the same thing as you want to do:

Chris Grigg

unread,
Oct 14, 2014, 11:59:35 AM10/14/14
to neo...@googlegroups.com
Even without ID or _classname property, `ModelName.first` and `ModelName.all.each` will work. They both use the labels to perform matches and when _classname is missing, the code falls back to labels to determine the appropriate class. I just did this and it worked:

```

2.1.3 :016 > Student.destroy_all

2.1.3 :017 > s = Student.create

2.1.3 :018 > s.neo_id

 => 2 

2.1.3 :019 > Neo4j::Session.query("MATCH (n:Student) SET n._classname = null").first

2.1.3 :020 > Neo4j::Session.query("MATCH (n:Student) SET n.uuid = null").first

2.1.3 :021 > s = Student.first

2.1.3 :022 > s.neo_id

 => 2 

```
You run into other problems when the ID is missing but not this one. It sounds to me like something else is going on here if you're not getting any results. Silly question here, this couldn't be an issue with the case of your labels, could it? You're using MOVIE, it's looking for Movie?

John Clegg

unread,
Oct 14, 2014, 2:38:11 PM10/14/14
to neo...@googlegroups.com
Hi Chris,

Yes, I did discover that labels were affecting it. eg. "Movies" works instead of "movies" I've fixed that now.

I have a lot of node data and would like to run the migration to add UUIDs to all my data. 

It seems to be trying to load migrations locally, should I copy them locally ?

John

Chris Grigg

unread,
Oct 14, 2014, 2:49:34 PM10/14/14
to neo...@googlegroups.com
Do you mean it’s trying to connect “http://localhost:7474” instead of what you have defined in your connection settings?

John Clegg

unread,
Oct 14, 2014, 4:32:49 PM10/14/14
to neo...@googlegroups.com
I'm using default - it's connecting to http://localhost:7474

John

Chris Grigg

unread,
Oct 14, 2014, 4:35:00 PM10/14/14
to neo...@googlegroups.com
That’s a little weird, it should use your app's connection settings, but not totally unsurprising since I threw that migration code together pretty quickly. ;-)
I’d definitely do it locally if you can anyway, though. It’ll be a bit faster.

John Clegg

unread,
Oct 15, 2014, 3:15:50 AM10/15/14
to neo...@googlegroups.com
FYI: 

I just checked the rake file against movie demo and I get the same result.

# rake neo4j:migrate[add_id_property,setup]

rake aborted!

LoadError: cannot load such file -- neo4j/tasks/neo4j_server.rake

I'm going to move the files locally and test it later.


John

Andreas Ronge

unread,
Oct 15, 2014, 6:16:31 AM10/15/14
to neo...@googlegroups.com
Hmm, it does work for me. Maybe you did not install all the gem (bundle install)
You can also try execute rake via bundler, e.g.

bundle exec rake -T


Chris Grigg

unread,
Oct 15, 2014, 7:47:57 AM10/15/14
to neo...@googlegroups.com
Another question, are you using Rails or some other rack framework? The migrations will only work with Rails. Andreas, I remember you were trying to get it going with Sinatra. Did you have any luck with that?

Also, John, what does your Rakefile look like? You should not have anything special in there related to this, it's all included automatically.

If it comes down to it, the migrations can be run through the Rails console. I can write up instructions on it later if you want, but if you peek in the rake file and the specs, you'll see how it works. Like I said, it was thrown together a bit hastily, so it's far from the most sophisticated code in the gem.

Andreas Ronge

unread,
Oct 15, 2014, 8:41:15 AM10/15/14
to neo...@googlegroups.com
@Chris: Yes, it does work without rails, I only use this:

gem 'sinatra'
gem 'neo4j', '~>3.0.1

Chris Grigg

unread,
Oct 15, 2014, 8:48:23 AM10/15/14
to neo...@googlegroups.com
Oh, cool!

John Clegg

unread,
Oct 15, 2014, 11:33:01 PM10/15/14
to neo...@googlegroups.com
Hi 

I'm using Padrino which is a sinatra framework based on Rack. But I went back to using the ruby neo4jrb code to test it.

Ahh ok . I saw the Rakefile in this https://github.com/neo4j-contrib/developer-resources/tree/gh-pages/language-guides/ruby/neo4jrb

There is no changes in the Rakefile from the github code. 


On Thursday, October 16, 2014 12:47:57 AM UTC+13, Chris Grigg wrote:
Another question, are you using Rails or some other rack framework? The migrations will only work with Rails. Andreas, I remember you were trying to get it going with Sinatra. Did you have any luck with that?

Also, John, what does your Rakefile look like? You should not have anything special in there related to this, it's all included automatically.

If it comes down to it, the migrations can be run through the Rails console. I can write up instructions on it later if you want, but if you peek in the rake file and the specs, you'll see how it works. Like I said, it was thrown together a bit hastily, so it's far from the most sophisticated code in the gem.

John
 
To unsubscribe from this group and stop receiving emails from it, send an email to neo4jrb+unsubscribe@googlegroups.com.

To post to this group, send email to neo...@googlegroups.com.
Visit this group at http://groups.google.com/group/neo4jrb.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "neo4jrb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4jrb+unsubscribe@googlegroups.com.

John Clegg

unread,
Oct 15, 2014, 11:33:53 PM10/15/14
to neo...@googlegroups.com
I'll check out what you running it from Bundle later tonight.

Cheers

John
To unsubscribe from this group and stop receiving emails from it, send an email to neo4jrb+unsubscribe@googlegroups.com.

To post to this group, send email to neo...@googlegroups.com.
Visit this group at http://groups.google.com/group/neo4jrb.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "neo4jrb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4jrb+unsubscribe@googlegroups.com.

To post to this group, send email to neo...@googlegroups.com.
Visit this group at http://groups.google.com/group/neo4jrb.
For more options, visit https://groups.google.com/d/optout.

John Clegg

unread,
Oct 16, 2014, 2:53:20 AM10/16/14
to neo...@googlegroups.com
I still can't get it to work. Is it my server version?

Here is my Server info

MacOSX10.9.4
neo4j 2.1.2 with spatial plugin

# ruby -v

ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]




Rakefile

load 'neo4j/tasks/neo4j_server.rake'

 

load
'neo4j/tasks/migration.rake'



bundle exec rake -T
rake neo4j:config[environment,port]          # Configure Server, e.g

 

rake neo4j
:info[environment]                 # Get info the Neo4j Server

rake neo4j
:install[edition,environment]      # Install Neo4j, example neo4j:install[community-2.1.3,development]

rake neo4j
:migrate[task_name,subtask]        # Run a script against the database to perform system-wide changes

rake neo4j
:reset_yes_i_am_sure[environment]  # Reset the Neo4j Server

rake neo4j
:restart[environment]              # Restart the Neo4j Server

rake neo4j
:start[environment]                # Start the Neo4j Server

rake neo4j
:stop[environment]                 # Stop the Neo4j Server


$ rake neo4j:migrate[add_id_property,setup]

rake aborted!

 

LoadError: cannot load such file -- neo4j/tasks/neo4j_server.rake

/Code/node/sinatra/Rakefile:1:in `load'


When I try using bundle

$ bundle exec rake neo4j:migrate[add_id_property,setup]

rake aborted!

 

Don't know how to build task 'environment'



Something is not right. 

John

Andreas Ronge

unread,
Oct 16, 2014, 9:55:46 AM10/16/14
to neo...@googlegroups.com
Aha, sorry. I never tested running the migrate task, I just assumed that it worked when I saw it using `rake -T`
Instead you have to manually run the cypher command.

Chris Grigg

unread,
Oct 16, 2014, 9:57:43 AM10/16/14
to neo...@googlegroups.com
I'm seeing if I can figure out how to make these work without requiring Rails. The big problem is that it needs the path to the config file. I wonder if the rake task can grab that and use it as an initialization argument?

Chris Grigg

unread,
Oct 16, 2014, 10:41:50 AM10/16/14
to neo...@googlegroups.com
Hey John, modify your gemfile to use this new branch.

gem 'neo4j', git: 'g...@github.com:neo4jrb/neo4j.git', branch: 'app-agnostic-migration'

The migration Rakefile now grabs the path from which the task is called and uses that instead of Rails.root. I just tested it in a Padrino app and it worked. I was using `bundle exec rake`, not sure if that'll make a difference for you.

John Clegg

unread,
Oct 17, 2014, 3:21:59 AM10/17/14
to neo...@googlegroups.com

Hi 


I'm still getting an error.

Gemfile

source 'https://rubygems.org'






gem
'sinatra'




#gem 'neo4j', '~>3.0.1' #git: 'g...@github.com:neo4jrb/neo4j.git'


gem
'neo4j', git: 'g...@github.com:neo4jrb/neo4j.git', branch: 'app-agnostic-migration'

group 'development' do

  gem
'pry'

  gem
'shotgun'

 

end


....

Using railties 4.1.6



Using neo4j 3.0.1 from git@github.com:neo4jrb/neo4j.git (at app-agnostic-migration)

Using slop 3.6.0

Using pry 0.10.1

Using rack-protection 1.5.3

Using shotgun 0.9

Using tilt 1.4.1

Using sinatra 1.4.5

 

Using bundler 1.7.3


$ rake neo4j:migrate[add_id_property,setup]

 

rake aborted
!

Don't know how to build task 'environment
'

/Users/john/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `eval'


/Users/john/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `<main>'

Tasks: TOP => neo4j:migrate

Chris Grigg

unread,
Oct 17, 2014, 9:37:54 AM10/17/14
to neo...@googlegroups.com
Can you upgrade to Ruby 2.1.X? You may also want to try doing `bundle exec rake` instead of just `rake`, not sure if that will make a difference. I tried this using Padrino and Ruby 2.1.5 and it worked.
...

Chris Grigg

unread,
Oct 17, 2014, 11:45:29 AM10/17/14
to neo...@googlegroups.com
Errr... Ruby 2.1.3. I swear I'm not from the future.

John Clegg

unread,
Oct 17, 2014, 4:02:03 PM10/17/14
to neo...@googlegroups.com
Johns-MacBook:sinatra john$ ruby -v

 

ruby
2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]

Johns-MacBook:sinatra john$ bundle exec rake neo4j:migrate[add_id_property,setup]

rake aborted
!

Don't know how to build task 'environment
'

/Users/john/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `eval'


/Users/john/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `<main>'


I'm running rvm on OSX . Something is strange. I'll give it a go on one of my linux boxes.

John

Chris Grigg

unread,
Oct 17, 2014, 4:17:30 PM10/17/14
to neo...@googlegroups.com
OK. I'm signed into skype as chrislgrigg if you want to try working through it that way.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';ret
...

John Clegg

unread,
Oct 17, 2014, 6:57:12 PM10/17/14
to neo...@googlegroups.com
Hi Chris,

Thanks for the offer. I'm in NZ timezone and have kids wrangling. I'll try you early next week. 

I'll work on migrating my API to neo4jrb in the meantime. 

John
Reply all
Reply to author
Forward
0 new messages