2008-12-17 16:49:06 +00:00
|
|
|
# --
|
2009-01-06 15:51:01 +00:00
|
|
|
# Copyright (C) 2008-2009 10gen Inc.
|
2008-11-22 01:00:51 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Affero General Public License, version 3, as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
|
|
|
# for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-12-17 16:49:06 +00:00
|
|
|
# ++
|
2008-11-22 01:00:51 +00:00
|
|
|
|
|
|
|
require 'mongo/db'
|
|
|
|
|
|
|
|
module XGen
|
|
|
|
module Mongo
|
|
|
|
module Driver
|
|
|
|
|
2008-12-17 16:43:08 +00:00
|
|
|
# Represents a Mongo database server.
|
2008-11-22 01:00:51 +00:00
|
|
|
class Mongo
|
|
|
|
|
|
|
|
DEFAULT_PORT = 27017
|
|
|
|
|
2009-01-14 23:37:28 +00:00
|
|
|
# Either nodes_or_host is a host name string and port is an optional
|
|
|
|
# port number that defaults to DEFAULT_PORT, or nodes_or_host is an
|
|
|
|
# array of arrays, where each is a host/port pair (or a host with no
|
2009-01-14 23:38:25 +00:00
|
|
|
# port). Finally, if nodes_or_host is nil then host is 'localhost' and
|
2009-01-14 23:37:28 +00:00
|
|
|
# port is DEFAULT_PORT. Since that's so confusing, here are a few
|
|
|
|
# examples:
|
|
|
|
#
|
|
|
|
# Mongo.new # localhost, DEFAULT_PORT
|
|
|
|
# Mongo.new("localhost") # localhost, DEFAULT_PORT
|
|
|
|
# Mongo.new("localhost", 3000) # localhost, 3000
|
|
|
|
# Mongo.new([["localhost"]]) # localhost, DEFAULT_PORT
|
|
|
|
# Mongo.new([["localhost", 3000]]) # localhost, 3000
|
|
|
|
# Mongo.new([["db1.example.com", 3000], ["db2.example.com", 3000]]])
|
|
|
|
#
|
|
|
|
# When a DB object first connects, it tries nodes and stops at the
|
|
|
|
# first one it connects to.
|
2009-01-15 14:29:38 +00:00
|
|
|
def initialize(nodes_or_host=nil, port=nil)
|
2009-01-14 23:37:28 +00:00
|
|
|
@nodes = case nodes_or_host
|
|
|
|
when String
|
|
|
|
[[nodes_or_host, port || DEFAULT_PORT]]
|
|
|
|
when Array
|
|
|
|
nodes_or_host.collect { |nh| [nh[0], nh[1] || DEFAULT_PORT] }
|
|
|
|
when nil
|
|
|
|
[['localhost', DEFAULT_PORT]]
|
|
|
|
end
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
|
2008-12-17 16:43:08 +00:00
|
|
|
# Return the XGen::Mongo::Driver::DB named +db_name+.
|
2008-11-22 01:00:51 +00:00
|
|
|
def db(db_name)
|
2009-01-14 23:37:28 +00:00
|
|
|
XGen::Mongo::Driver::DB.new(db_name, @nodes)
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
|
2008-12-17 16:43:08 +00:00
|
|
|
# Not implemented.
|
2008-11-22 01:00:51 +00:00
|
|
|
def clone_database(from)
|
|
|
|
raise "not implemented"
|
|
|
|
end
|
|
|
|
|
2008-12-17 16:43:08 +00:00
|
|
|
# Not implemented.
|
2008-11-22 01:00:51 +00:00
|
|
|
def copy_database(from_host, from_db, to_db)
|
|
|
|
raise "not implemented"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|