7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/map_reduced/config.rb', line 7
def database=(string)
begin
if string.match /^.+\:\/\/.+/
uri = URI.parse(string)
connection = Mongo::Connection.new(uri.host, uri.port)
database = uri.path.gsub(/^\//, "")
if uri.user && uri.password
connection.add_auth(database, uri.user, uri.password)
connection.apply_saved_authentication
end
@db = connection.db(database)
else
@db = Mongo::Connection.new.db(string)
end
rescue Mongo::ConnectionFailure => e
raise Mongo::ConnectionFailure, "#{e}\nIt is possible that your database string is badly formed.\nIt should either be a database name (for localhost connections), or a fully-formed remote connection like mongodb://user:pass@host:port/database"
end
end
|