How to load node details after a query

52 views
Skip to first unread message

Paolo Di Pietro

unread,
Aug 22, 2014, 2:58:19 PM8/22/14
to neo...@googlegroups.com
I'm using Neo4j 2.0.1 and Neo4j.rb 3.0

I've the following query:

    xxx = Neo4j::Session.query('match (q:Complex_Type)<-[:_IS_A]-(m) return m;')

with the following partial results:
   
    outgoing_relationships: http://localhost:7474/db/data/node/25/relationships/out
    labels: http://localhost:7474/db/data/node/25/labels

Now, going ahead, which is the correct way to obtain labels?

1) it is possible without using get & post?
2) If I need to use get or post, which is the correct way to run the query?

(I wasn't able to use a Neo4j::Server::Neo4jServerEndpoint because not initialised, but I cannot initialize it because initialize is a private method ;-( )


TIA

Paolo

Andreas Ronge

unread,
Aug 22, 2014, 4:27:56 PM8/22/14
to neo...@googlegroups.com
Hi

Not sure I understand the question since I get a different response from the query method. 
Why not just use the labels method ?  

The labels method does require another server request (unless you are using the embedded db of course)

[2] pry(main)> s = Neo4j::Session.open

[21] pry(main)> n = s.query("start n=node(1) return n").first[:n].labels

=> [:person]


Also, have a look at the query DSL: https://github.com/andreasronge/neo4j-core#cypher-queries

/Andreas



--
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.

Paolo Di Pietro

unread,
Aug 22, 2014, 5:45:11 PM8/22/14
to neo...@googlegroups.com
I would like ....

this is the code:
<% s = Neo4j::Session.open %>
<%= s.query("start n=node(1) return n").first[:n].labels %>

 but this is the result ,-)

Started GET "/" for 127.0.0.1 at 2014-08-22 23:41:28 +0200
Processing by StaticPagesController#home as HTML
  Rendered static_pages/home.html.erb within layouts/application (6.0ms)
  Rendered layouts/_shim.html.erb (3.0ms)
  Rendered layouts/_header.html.erb (347.0ms)
  Rendered shared/_alert_message.html.erb (4.0ms)
  Rendered shared/_left1.html.erb (1078.0ms)
Completed 500 Internal Server Error in 5147ms

ActionView::Template::Error (undefined method `labels' for #<Hash:0x73922355>):
    89: <% s = Neo4j::Session.open %>
    90: <%= s.query("start n=node(1) return n").first[:n].labels %>
    91:
    92:
  app/views/shared/_left1.html.erb:92:in `_app_views_shared__left__html_erb__1125271557_5628'
  app/views/layouts/application.html.erb:15:in `_app_views_layouts_application_html_erb___1962231266_5552'

Andreas Ronge

unread,
Aug 23, 2014, 2:00:59 AM8/23/14
to neo...@googlegroups.com
Hi

Which version are you using of neo4j-core ?
The latest released is 3.0.0.alpha.19

Paolo Di Pietro

unread,
Aug 23, 2014, 12:50:28 PM8/23/14
to neo...@googlegroups.com
This was the actual situation:

neo4j (3.0.0.alpha.7, 3.0.0.alpha.3, 2.3.0 java)
neo4j-community (2.1.1, 2.0.1, 2.0.0 java, 1.9.5 java)
neo4j-core (3.0.0.alpha.16, 3.0.0.alpha.8, 2.3.0 java)
neo4j-cypher (1.0.3)
neo4j-wrapper (2.3.0 java)

I updated the gems, but, while restarting, I got an initialization error ...

pdipietro@CUC-N4J-V4-0-0:~/gsn$ rake neo4j:start
Starting Neo4j...
pdipietro@CUC-N4J-V4-0-0:~/gsn$ rails s
=> Booting WEBrick
=> Rails 4.0.3 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
NameError: uninitialized constant Neo4j::ActiveNode
pdipietro@CUC-N4J-V4-0-0:~/gsn$

My gemfile is:

actionmailer (4.1.5, 4.0.3)
actionpack (4.1.5, 4.0.3, 3.2.17)
actionview (4.1.5)
active_attr (0.8.4, 0.8.3, 0.8.2)
activemodel (4.1.5, 4.0.3, 3.2.17)
activerecord (4.1.5, 4.0.3)
activerecord-deprecated_finders (1.0.3)
activesupport (4.1.5, 4.0.3, 3.2.17)
arel (5.0.1.20140414130214, 4.0.2)
assert_difference (0.5.0)
atomic (1.1.16 java, 1.1.15 java)
bcrypt (3.1.7 java)
bcrypt-ruby (3.1.5 java)
bootstrap-sass (3.2.0.1, 3.2.0.0, 3.1.1.0)
bootstrap-will_paginate (0.0.10)
builder (3.2.2, 3.1.4, 3.0.4)
bundler (1.7.1, 1.5.3)
capybara (2.4.1, 2.3.0, 2.2.1)
celluloid (0.15.2)
celluloid-io (0.15.0)
childprocess (0.5.3, 0.5.2, 0.5.1)
coderay (1.1.0)
coffee-rails (4.0.1)
coffee-script (2.3.0, 2.2.0)
coffee-script-source (1.7.1, 1.7.0)
cucumber (1.3.16, 1.3.14)
database_cleaner (1.3.0, 0.7.0)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.2.1, 2.0.2)
factory_girl (4.4.0)
factory_girl_rails (4.4.1)
faker (1.4.3, 1.4.1, 1.3.0, 1.2.0)
faraday (0.9.0)
ffi (1.9.3 java)
formatador (0.2.5, 0.2.4)
gherkin (2.12.2 java)
growl (1.0.3)
guard (2.6.1, 2.6.0, 2.5.1)
guard-rspec (4.3.1, 4.2.10, 4.2.8)
guard-spork (1.5.1)
hashie (3.2.0, 2.1.2, 2.1.0, 2.0.5)
hike (2.1.3, 1.2.3)
httparty (0.13.1, 0.13.0)
i18n (0.6.11, 0.6.9)
jbuilder (2.1.3, 1.5.3)
journey (1.0.4)
jquery-minicolors-rails (2.1.4.0, 2.1.1.2)
jquery-rails (3.1.1, 3.1.0)
jruby-launcher (1.1.0 java, 1.0.19 java)
json (1.8.1 java)
jwt (1.0.0, 0.1.11)
listen (2.7.9, 2.7.1, 2.7.0)
lumberjack (1.0.9, 1.0.5, 1.0.4)
mail (2.6.1, 2.5.4)
method_source (0.8.2)
mime-types (2.3, 1.25.1)
mini_portile (0.6.1, 0.5.3, 0.5.2)
minitest (5.4.0, 4.7.5)
multi_json (1.10.1, 1.9.2, 1.9.0)
multi_test (0.1.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
neo4j (3.0.0.alpha.7, 3.0.0.alpha.3, 2.3.0 java)
neo4j-community (2.1.3, 2.1.1, 2.0.1, 2.0.0 java, 1.9.5 java)
neo4j-core (3.0.0.alpha.19, 3.0.0.alpha.16, 3.0.0.alpha.8, 2.3.0 java)
neo4j-cypher (1.0.3)
neo4j-wrapper (2.3.0 java)
nio4r (1.0.0 java)
nokogiri (1.6.3.1 java, 1.6.2.1 java, 1.6.1 java)
oauth (0.4.7)
oauth2 (1.0.0, 0.9.4, 0.9.3)
omniauth (1.2.2, 1.2.1)
omniauth-facebook (2.0.0, 1.6.0)
omniauth-gplus (2.0.1, 1.2.0)
omniauth-linkedin (0.2.0, 0.1.0)
omniauth-oauth (1.0.1)
omniauth-oauth2 (1.2.0, 1.1.2)
omniauth-twitter (1.0.1)
orm_adapter (0.5.0, 0.4.1)
os (0.9.6)
polyglot (0.3.5, 0.3.4)
pry (0.10.1 java, 0.10.0 java, 0.9.12.6 java)
rack (1.5.2, 1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (4.0.3)
railties (4.0.3, 3.2.17)
rake (10.3.2, 10.2.2, 10.2.0, 10.1.1)
rb-fsevent (0.9.4)
rb-inotify (0.9.5, 0.9.3)
rdoc (4.1.1, 3.12.2)
rmagick4j (0.3.8)
rspec (3.0.0, 2.14.1)
rspec-core (3.0.4, 3.0.2, 2.14.8)
rspec-expectations (3.0.4, 3.0.2, 2.14.5)
rspec-mocks (3.0.4, 3.0.2, 2.14.6)
rspec-rails (3.0.2, 3.0.1, 2.14.2, 2.14.1)
rspec-support (3.0.4, 3.0.2)
rubyzip (1.1.6, 1.1.4, 1.1.3, 1.1.2, 1.1.0)
sass (3.3.2, 3.2.19, 3.2.18, 3.2.14)
sass-rails (4.0.3, 4.0.2, 4.0.1)
sdoc (0.4.0)
selenium-webdriver (2.42.0, 2.41.0, 2.40.0)
slop (3.6.0, 3.5.0, 3.4.7)
spoon (0.0.4)
spork (1.0.0rc4)
spork-rails (4.0.0)
sprockets (2.11.0, 2.2.2)
sprockets-rails (2.0.1)
therubyrhino (2.0.4, 2.0.3)
therubyrhino_jar (1.7.4)
thor (0.19.1, 0.18.1)
thread_safe (0.3.4 java, 0.3.3 java, 0.3.1 java, 0.2.0 java)
tilt (1.4.1)
timers (1.1.0)
treetop (1.4.15)
turbolinks (2.3.0, 2.2.2, 2.2.1)
tzinfo (1.2.2, 0.3.41, 0.3.40, 0.3.39, 0.3.38)
uglifier (2.5.3, 2.5.1, 2.5.0, 2.4.0)
websocket (1.0.7)
will_paginate (3.0.5)
xpath (2.0.0)
zip (2.0.2)

and this is my application.rb (note: I needed to comment #config.neo4j.storage_path = "/tmp/neo4j-#{Rails.env}.db"
that was running before!

require File.expand_path('../boot', __FILE__)
require "rails"

%w(
  neo4j
  neo4j-core
    action_controller
  action_mailer
  sprockets
).each do |framework|
  begin
    require "#{framework}/railtie"
  rescue LoadError
  end
end

Bundler.require(:default, Rails.env)

module GSN
  class Application < Rails::Application
    I18n.enforce_available_locales = true

    # Enable Neo4j generators, e.g:  rails generate model Admin --parent User
    config.generators do |g|
      g.orm             :neo4j
      g.test_framework  :rspec, fixture: false
    end

    #config.neo4j.storage_path = "/tmp/neo4j-#{Rails.env}.db"

    config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
  end
end

Andreas Ronge

unread,
Aug 23, 2014, 4:40:27 PM8/23/14
to neo...@googlegroups.com
Hi

Can you compare you application with this example rails app: https://github.com/andreasronge/neo4j/tree/master/example/blog
I guess there is a problem in your Gemfile, the application.rb file looks ok (but you don't need to include the neo4j-core since it is already included and does not have a ralitie).
In the Gemfile you should lock the neo4j gem to version 3.0.0.alpha.11

Paolo Di Pietro

unread,
Aug 23, 2014, 6:20:12 PM8/23/14
to neo...@googlegroups.com
Andreas,

Just a fast answer to tell you that, after locking the neo4j to version 3.0.0.alpha.11, the sistem, at least, is started.
I wish to thank you a lot for your help.
I'll let you know how the work will proceed.

TY again

Paolo
Message has been deleted
Message has been deleted

Paolo Di Pietro

unread,
Aug 25, 2014, 6:24:04 AM8/25/14
to neo...@googlegroups.com
Hi,

here I am again :-(

This is my results now:

[2] pry(#<#<Class:0x1023784b>>)> s = Neo4j::Session.open
=> Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.0.0'
[3] pry(#<#<Class:0x1023784b>>)> n = s.query("start n=node(1) return n").first[:n].labels
NoMethodError: undefined method `new' for nil:NilClass
from /home/pdipietro/.rbenv/versions/jruby-1.7.9/lib/ruby/gems/shared/gems/neo4j-3.0.0.alpha.11/lib/neo4j/active_node/node_wrapper.rb:7:in `wrapper'
[4] pry(#<#<Class:0x1023784b>>)>

I noticed that I'm running Neo4j 2.0.0 while having the following gems loaded:
    neo4j (3.0.0.alpha.11, 3.0.0.alpha.7, 3.0.0.alpha.3, 2.3.0 java)

    neo4j-community (2.1.3, 2.1.1, 2.0.1, 2.0.0 java, 1.9.5 java)
    neo4j-core (3.0.0.alpha.19, 3.0.0.alpha.16, 3.0.0.alpha.8, 2.3.0 java)
    neo4j-cypher (1.0.3)
    neo4j-wrapper (2.3.0 java)

Is it correct or is better to move to another version? If yes, how can I change Noo4j version of my application?

Thank you

Paolo

BTW



Can you compare you application with this example rails app: https://github.com/andreasronge/neo4j/tree/master/example/blog

The application doen't run

Got an error with bundle
 
pdipietro@CUC-N4J-V4-0-0:~/
neo4j/neo4j/example/blog$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Bundler could not find compatible versions for gem "neo4j-community":
  In Gemfile:
    neo4j (>= 0) java depends on
      neo4j-core (= 3.0.0.alpha.19) java depends on
        neo4j-community (~> 2.1.1) java

    neo4j-community (2.0.0)

replacing the reference with

  gem 'neo4j-community', '~> 2.1.2'

---------------------------------------
I also added

  gem 'therubyrhino'

then the demo program starded.

So if you like you can adjust the docs.

Paolo

Chris Grigg

unread,
Aug 28, 2014, 9:26:54 AM8/28/14
to neo...@googlegroups.com
I believe we found the source of this bug and pushed a fix in the Release Candidate.
Reply all
Reply to author
Forward
0 new messages