DSL for building MongoDB queries, updates and aggregations
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
features
lib
spec
.gitignore
.travis.yml
Gemfile
Gemfile.lock
LICENSE.md
README.md
Rakefile
daodalus.gemspec

README.md

DAODALUS Build Status Code Climate

Construct complex MongoDB queries, updates and aggregations.

Configuration:

# config/mongo.yml
development:
  animals:
    database: animals_development
    host: localhost
    pool_size: 5
    timeout: 5
    replicate_set_name: animals_development
    servers:
      - { host: localhost, port: 27017 }

Initialisation:

# config/initializers/daodalus.rb
Daodalus::Configuration.load('config/mongo.yml', Rails.env)
Examples:
#!ruby
class CatDAO
  extend Daodalus::DAO # or `include` if you want an instance of a DAO
  target :animals, :cats # or overide `connection` to supply your own

  def self.example_find
    select(:name).where(:paws).less_than(4).find
  end

  def self.example_find_one
    where(:collar_id).eq("aochc986").find_one
  end

  def self.example_update
    set(:stray, true).where(:address).does_not_exist.update
  end

  def self.example_find_and_modify
    dec(:lives).
      push(:names, "Kitty").
      where(:stray).eq(true).
      and(:cuteness).gt(8).
      find_and_modify(new: true)
  end

  def self.example_remove
    where(:lives).eq(0).remove
  end

  def self.example_aggregation
    match(:lives).gt(3).
      and(:address).exists.
      unwind(:favourite_foods).
      group(:favourite_foods).
      min(min_paws: 'paws').
      sort(:_id).
      limit(10).
      project(:_id).as(:food).and(:min_paws).
      aggregate
  end
end

License

Daodalus is Copyright © 2012 On The Beach Ltd. It is free software, and may be redistributed under the terms specified in the LICENSE file.