public
Description: Adapter to use the MongoDB with Rail's ActiveRecord
Homepage:
Clone URL: git://github.com/mongodb/activerecord-mongo-adapter.git
name age message
file .gitignore Mon Jun 22 07:48:50 -0700 2009 LICENSE is Apache 2 not AGPL [Mike Dirolf]
file LICENSE Mon Jun 22 07:48:50 -0700 2009 LICENSE is Apache 2 not AGPL [Mike Dirolf]
file README.rdoc Tue Aug 11 06:28:33 -0700 2009 MINOR: update readme [Mike Dirolf]
file Rakefile Thu Jan 22 07:25:52 -0800 2009 initial checkin of plugin code [jimm]
file init.rb Wed Aug 26 11:45:36 -0700 2009 use Mongo::Connection instead of deprecated Mon... [Mike Dirolf]
file install.rb Thu Jan 22 07:25:52 -0800 2009 initial checkin of plugin code [jimm]
directory lib/ Mon Sep 14 11:30:40 -0700 2009 implement establish_connection - allows passeng... [Mike Dirolf]
directory tasks/ Thu Jan 22 07:25:52 -0800 2009 initial checkin of plugin code [jimm]
directory test/ Thu Aug 27 11:38:18 -0700 2009 fix for superfluous Rollback exception on faile... [Mike Dirolf]
file uninstall.rb Thu Jan 22 07:25:52 -0800 2009 initial checkin of plugin code [jimm]
README.rdoc

ActiveRecord for Mongo

This plugin provides an ActiveRecord connection adapter for Mongo (www.mongodb.org/).

This plugin relies on the "mongo" Ruby Gem, which can be found at github.com/mongodb/mongo-ruby-driver. See the README file there for installation instructions.

After installing this plugin, you will need a db/schema.rb file and a database.yml file. See below for instructions.

Installing

As noted above, this plugin requires the "mongo" Ruby Gem, version 0.11 or higher.

To add this plugin to your Rails app, move (or link) this directory into your Rails app’s vendor/plugins directory and name it mongo_record. In other words, this README.rdoc file should be

  RAILS_ROOT/vendor/plugins/mongo_record/README.rdoc

Schema

ActiveRecord requires a schema, but Mongo is a schema-free database. This means that you have to supply this plugin with a schema for your Mongo database that ActiveRecord can use.

This plugin reads the file named by ENV[‘SCHEMA’] or, if that is not defined, db/schema.rb to get the database schema the application wants to use.

Sample schema.rb

In case you need to hand-generate a schema file (for example, you don’t have a db/schema.rb file generated by "rake db:schema:dump", here is a small sample.

  ActiveRecord::Schema.define(:version => 0) do

    create_table "students", :force => true do |t|
      t.column "name", :string, :null => false
    end

    create_table "addresses", :force => true do |t|
      t.column "student_id", :integer, :null => false
      t.column "street", :string
      t.column "city", :string
      t.column "state", :string
      t.column "postal_code", :string
    end

    add_index "addresses", ["student_id"], :name => "fk_addresses_students"

    create_table "courses", :force => true do |t|
      t.column "name",     :string
    end

    create_table "scores", :force => true do |t|
      t.column "student_id", :integer, :null => false
      t.column "course_id", :integer, :null => false
      t.column "grade", :float, :null => false
    end

  end

Sample database.yml

  development:
    adapter: mongo
    database: foo_development

  test:
    adapter: mongo
    database: foo_test

  production:
    adapter: mongo
    database: foo_production

Optional Logging

If you wish, you can use a Mongo capped collection for Rails log messages. To do so, edit the file init.rb and uncomment the code following the comment that says "Uncomment the following to log to Mongo using a capped collection." See MongoRecord::LogDevice for details.

If enabled, log messages are sent to the capped collection named rails_log_{RAILS_ENV}.

Copyright

Copyright 2009 10gen, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.