require 'mongo' module Ganymed # @private class MongoDB attr_reader :config def initialize(config) @config = config @collections = {} log.info("using MongoDB at #{config.host}:#{config.port}/#{config.database}") end def connection @connection ||= ::Mongo::Connection.new(config.host, config.port, :pool_size => 5, :pool_timeout => 5) end def db @db ||= connection.db(config.database) end def collection(ns) @collections[ns] ||= db[ns].tap do |col| col.ensure_index([['c', ::Mongo::ASCENDING]]) col.ensure_index([['o', ::Mongo::ASCENDING]]) col.ensure_index([['t', ::Mongo::ASCENDING]]) col.ensure_index([['c', ::Mongo::ASCENDING], ['o', ::Mongo::ASCENDING]]) col.ensure_index([['o', ::Mongo::ASCENDING], ['t', ::Mongo::ASCENDING]]) col.ensure_index([['c', ::Mongo::ASCENDING], ['o', ::Mongo::ASCENDING], ['t', ::Mongo::ASCENDING]], :unique => true) end end def method_missing(method, *args, &block) db.__send__(method, *args, &block) end end end