ruby-on-railsneo4jneo4j.rb

Use two neo4j databases in single rails app


I have two neo4j databases running on two different hosts. I connected my rails app to one of them while generating the app. Now I want to use other database as well with the app. How can I configure the app to connect to both the databases?


Solution

  • There’s not currently a good way to configure one Ruby process to use two sessions at the same time. If you are using Rails you can change the server by setting the NEO4J_URL environment variable. Otherwise you’d need to manage the session by setting Neo4j::ActiveBase.current_session or Neo4j::ActiveBase.on_establish_session (which will set the session for each new thread, which may be needed if you are running a multi-threaded process)

    See: https://github.com/neo4jrb/neo4j/blob/master/lib/neo4j/active_base.rb