'fixes sublimetext color bug, ignore

What is Neo4j.rb?

The Neo4j.rb project is made up of the follow Ruby gems:

  • activegraph A Object-Graph-Mapper (OGM) for the Neo4j graph database. It tries to follow API conventions established by ActiveRecord and familiar to most Ruby developers but with a Neo4j flavor.
  • neo4j-ruby-driver A low level driver for connecting to Neo4j. Used by the activegraph gem.
  • neo4j-rake_tasks) A set of rake tasks for installing and managing a Neo4j database within your project.


(software) A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.


(computer science) A graph database stores data in a graph, the most generic of data structures, capable of elegantly representing any kind of data in a highly accessible way.


(databases) The world's leading graph database

If you're already familiar with ActiveRecord, DataMapper, or Mongoid, you'll find the Object Model features you've come to expect from an O*M:

  • Properties
  • Indexes / Constraints
  • Callbacks
  • Validation
  • Assocations
Because relationships are first-class citizens in Neo4j, models can be created for both nodes and relationships.

Additional features include

  • A chainable arel-inspired query builder
  • Transactions
  • Migration framework


  • Ruby 2.5+ (tested in MRI and JRuby)
  • Neo4j 3.4+

Latest News

News Archive

Get started


New to Ruby? Try Ruby in your browser!

Installation resources:


New to Neo4j? Try Neo4j in your browser!

Installation resources:

Introduction screencast

Ruby Rogues interview

Brian Underwood, one of the former maintainers of the Neo4j.rb project, gave an interview with the Ruby Rogues. See episode #236.


In your Gemfile

gem 'activegraph'
gem 'neo4j-ruby-driver'

A sample ActiveNode model

 class User
    include ActiveGraph::Node

    property :name
    property :age, type: Integer

    has_many :out, :friends, type: :friends_with, model_class: 'User'
    has_one :in,   :github_profile, type: :linked_to  # model_class: 'GithubProfile' assumed

Using query chaining to get the github profiles for a user's friends


If you're the sort who likes to watch a video, check out our intro screencast.
If you like to read, check out our documentation's setup page.

Simple queries

If you just want to execute some raw cypher queries you can do the following.

  ActiveGraph::Base.driver =

  me = ActiveGraph::Base.query('MATCH (found:User) WHERE found.name = {aName} RETURN found', aName: 'Andreas').first.found

There is also a query-building API which allows you to build cypher queries with method chaining:

  user = ActiveGraph::Base.query.match(found: :User)
                                .where(found: {name: 'Andreas'})

At each step in the chain a query object is returned which is also Enumerable. See the documentation for more info.

Also note that with the query chaining there is no need to use params (which are important for efficient neo4j queries). They will be used in the background in this case.

Install in Ruby on Rails

In your config/application.rb

  config.neo4j.driver.url = ENV['NEO4J_URL'] || 'neo4j://localhost:7687'
  config.neo4j.driver.username = 'user'
  config.neo4j.driver.password = 'password'

Getting involved

Like any open source project we happily welcome:

You can also join us on our mailing list

Getting Help

Need help using the gem? Think you've found a bug? There are a few ways to get help.

Source code of this site

If you notice anything wrong with this page, feel free to submit a pull request on the repository