Created
February 7, 2012 15:46
-
-
Save mranallo/1760327 to your computer and use it in GitHub Desktop.
Mongo Connection Id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mongodb | |
def self.db | |
config = Rails.configuration.database_configuration["mongodb_#{Rails.env}"] | |
host = config["host"] | |
database = config["database"] | |
username = config["username"] | |
password = config["password"] | |
port = config["port"] | |
if Rails.env == "development" | |
@@connection ||= Mongo::Connection.new host, port, :logger => Rails.logger, :safe => true | |
else | |
host.each { |h| h[1] << port } | |
@@connection ||= Mongo::ReplSetConnection.new(host["primary"], host["secondary"], :logger => Rails.logger, :refresh_mode => :sync) | |
end | |
@@db ||= @@connection[database] | |
unless username.nil? || password.nil? | |
@@db.authenticate(username, password) | |
end | |
@@db | |
end | |
def self.sent_email | |
@collection ||= Mongodb.db['sent_email'] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment