Skip to content
Go to file
This branch is 3 commits ahead, 216 commits behind couchrest:master.

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

CouchBase Model: CouchBase, working on the new CouchBase Server

CouchBase Models, built from CouchBase Model is an effort to provide model interface on the offical ruby gem for couchbase - couchbase-ruby-client. WARNING: This is still in early stages of transformation and yet not ready for use.


General API:

See the update history for an up to date list of all the changes we've been working on recently.

Notes on CouchRest Model

Originally called ExtendedDocument, the new Model structure uses ActiveModel, part of Rails 3, for validations and callbacks.

If your project is still running Rails 2.3, you'll have to continue using ExtendedDocument as it is not possible to load ActiveModel into programs that do not use ActiveSupport 3.0.

CouchRest Model is only properly tested on CouchDB version 1.0 or newer.

WARNING: As of April 2011 and the release of version 1.1.0, the default model type key is 'type' instead of 'couchbase-type'. Simply updating your project will not work unless you migrate your data or set the configuration option in your initializers:

CouchBase::Model::Base.configure do |config|
  config.model_type_key = 'couchbase-type'

This is because CouchBase Model's are not couchbase specific and may be used in any other systems such as Javascript, the model type should reflect this. Also, we're all used to type being a reserved word in ActiveRecord.



$ sudo gem install couchbase_model


If you're using bundler, define a line similar to the following in your project's Gemfile:

gem 'couchbase_model'


CouchBase Model is configured to work out the box with no configuration as long as your CouchDB instance is running on the default port (8091) on localhost. The default name of the database is either the name of your application as provided by the Rails.application.class.to_s call (with /application removed) or just 'couchbase' if none is available.

The library will try to detect a configuration file at config/couchbase.yml from the Rails root or Dir.pwd. Here you can configuration your database connection in a Rails-like way:

  protocol: 'https'
  port: 443
  prefix: project
  suffix: test
  username: test
  password: user

Note that the name of the database is either just the prefix and suffix combined or the prefix plus any text you specifify using use_database method in your models with the suffix on the end.

The example config above for example would use a database called "project_test". Heres an example using the use_database call:

class Project < CouchBase::Model::Base
  use_database 'sample'

# The database object would be provided as:
Project.database     #=> ""



$ rails generate couchbase_model:config


$ rails generate model person --orm=couchbase_model

General Usage

require 'couchbase_model'

class Cat < CouchBase::Model::Base

  property :name,      String
  property :lives,     Integer, :default => 9

  property :nicknames, [String]


  view_by :name


@cat = => 'Felix', :nicknames => ['so cute', 'sweet kitty'])   # true

@cat['name']   # "Felix"

@cat.nicknames << 'getoffdamntable'

@cat =
@cat.update_attributes(:name => 'Felix', :random_text => 'feline') # false
@cat.random_text  # Raises error!



CouchBase Model now comes with a Gemfile to help with development. If you want to make changes to the code, download a copy then run:

bundle install

That should set everything up for rake spec to be run correctly. Update the couchbase_model.gemspec if your alterations use different gems.


The most complete documentation is the spec/ directory. To validate your CouchBase install, from the project root directory run bundle install to ensure all the development dependencies are available and then rspec spec or bundle exec rspec spec.

We will not accept pull requests to the project without sufficient tests.


Please post bugs, suggestions and patches to the bug tracker at

Follow us on Twitter:

Also, check


Doing the simple stuff so you don't have to



You can’t perform that action at this time.