-
Notifications
You must be signed in to change notification settings - Fork 276
Neo4j::Rails Config
You can set the location of the database in the config/application.rb
file.
Example:
config.neo4j.storage_path = "#{config.root}/db/neo4j-#{Rails.env}"
config.neo4j.timestamps = false # disable automatic timestamps on updated_at and created_at properties
The rails console will start up in read-only mode if you already have a running rails application since Neo4j does not allow write access to the database from several processes.
As a workaround you can use Neo4j HA which will replicate databases between processes.
To enable write access from a rails console using Neo4j HA:
- add development dependencies to your Gemfile: neo4j-advanced and neo4j-enterprise (check license)
- in your application/config.rb, add
require 'neo4j/rails/ha_console/railtie' if Rails.env.development?
- in config/application.rb : `config.neo4j.storage_path = … unless Rails.env.development?`
This will start a zookeeper process, configure the database location and configure Neo4j to use HA.
To shutdown the zookeeper:
Neo4j::Rails::HaConsole.shutdown_zookeeper
This is currently not released yet (use latest source from Github).
- Installing JRuby – see RVM
- Tomcat/Trinidad
- “TorqueBox”
- Glassfish App Server
Trinidad needs the Java jar files in the lib folder.
There is a script for doing this:
neo4j-jars -local
Just type neo4j-jars
for help
If you forget to add those jar files to your rails project you may get the following error message:
No index provider 'lucene' found
Add the following line in your config/application.rb file:
config.neo4j.online_backup_enabled = true
Then add the correct jar files to the lib folder:
neo4j-jars -backup
To perform the backup
require 'neo4j'
Neo4j.load_online_backup
Neo4j::OnlineBackup('localhost').incremental('/var/backup')
See the example – https://github.com/andreasronge/neo4j/tree/master/example/ha-cluster
Example of a config/application.rb file:
config.neo4j['ha.db']=true config.neo4j['ha.server_id']=1 config.neo4j['ha.server'] = 'localhost:6001' config.neo4j['ha.coordinators] = 'localhost:2181,localhost:2182,localhost:2183'
Then add the correct jar files to the lib folder (when using a servlet container):
cd YOUR_RAILS_ROOT
neo4j-jars enterprise
Add the neo4j-advanced and neo4j-enterprise gems to your Gemfile.
Notice, if you are trying to create a new HA database you need to set the
configuration option `keep_logical_logs=true` and then create a transaction on the master, or copy the complete database to the new HA instance (I think …). Make sure the nioneo_logical.log.vXX files are available on the server db.
You probably for forgot to run neo4j-jars command to copy the jar files to the lib folder.
This is normally needed for trinidad and warbler deployments.
See deployment above.
You get this exception if there is already an neo4j db instance running.
Only one write instance of the database is possible. If there is already a write instance running then a read only db will be created.
Did you run the rails console before you did the first request to rails ?
Yes and it is enabled by default (in >= 2.0.0). Read more about it here: the identity map
and Neo4j::IdentityMap
Because you have not enabled identity map, see above.
Let say you have the following class:
class Person < Neo4j::Rails::Model
has_one(:nested)
end
node = Person.create
node.nested = Person.create
node.save
Then you can’t update the node.nested
node.nested[:some_property] = 'some value'
node.nested.nested << other_node
node.nested.save
Instead you must use a temporary variable, like this:
tmp = node.nested
tmp[:some_property] = 'some value'
tmp.nested << other_node
tmp.save
The reason is that the node.nested
creates a new instance of a
wrapped node.
However, the following will work:
n = Person.create
n.nested = Person.create
n.nested[:name] = 'foo'
n.save
n.nested[:name] # => 'foo'
You do not need a temporary variable in this case since the relationship is not
persisted yet.
WARNING: Much of the information in this wiki is out of date. We are in the process of moving things to readthedocs
- Project Introduction
- Neo4j::ActiveNode
- Neo4j::ActiveRel
- Search and Scope
- Validation, Uniqueness, and Case Sensitivity
- Indexing VS Legacy Indexing
- Optimized Methods
- Inheritance
- Core: Nodes & Rels
- Introduction
- Persistence
- Find : Lucene
- Relationships
- Third Party Gems & extensions
- Scaffolding & Generators
- HA Cluster