Project

mini_mongo

0.01
No commit activity in last 3 years
No release in over 3 years
Basics Object Mapper for Mongo
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

~> 1.9.2
 Project Readme

Build Status

MiniMongo

A Ruby Object Mapper for Mongo

Installation

Ruby Versions

This ODM works and is consistently tested on: CRuby 1.9.x-2.x, JRuby (in 1.9 mode) and Rubinius (in 1.9 mode). CRuby 2.0 isn't supported right now since bson_ext dependency is failing during install.

We don't have plans to support 1.8.x rubies

Gems

Add this line to your application's Gemfile:

gem 'mini_mongo'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install mini_mongo

Usage

Configuring

To get started configure the ODM with your db info using your database url

MiniMongo.configure do |config|
  config.database_url = "mongodb://:@localhost:27017/posts"
  config.slave_ok = true # by default is false
end

or passing directly all the params

MiniMongo.configure do |config|
  config.db_name = "posts"
  config.db_user = ""
  config.db_password = ""
  config.db_host = "localhost"
  config.db_port = "27017"
end

Mapping

require "mini_mongo"
MiniMongo.configure do|config|
  config.database_url = "mongodb://:@localhost:27017/posts"
end

class Post < MiniMongo::Base
  maps :posts
end

### Examples
# Post.insert({:author => "Chuck Norris"})
# => #<Post:0x007fe5240f42c0 @id="5016af53bda74305f1000002", @author="Chuck Norris">

# Post.find("id" => "5016af53bda74305f1000002")
# => #<Post:0x007fe5240cc360 @id="5016af53bda74305f1000002", @author="Chuck Norris">
#
# Find cursor method sort, limit and skip support
# Post.find({"id" => "5016af53bda74305f1000002"}, {:limit => 1})
# => #<Post:0x007fe5240cc363 @id="5016af53bda74305f1000003", @author="Bruce Lee">
#
# Post.update("5016af53bda74305f1000002", "author" => "chuck norris")
# => #<Post:0x007fdc7c171c80 @author="chuck norris", @id="5016af53bda74305f1000002">
#
#Post.count
# => 1
#
#Post.remove("5016af53bda74305f1000002")
# => true
#
#Post.remove_all
# => true

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request