Class: Monga::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/monga/client.rb

Constant Summary collapse

VALID_OPTS =
[:host, :port, :server, :type, :pool_size, :servers, :read_pref, :timeout]

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Following options are allowed

  • host - host of server to connect, default 127.0.0.1

  • port - port of server to connect, default 27017

  • server - host:port of server to connect (you can pass server or host/port pair)

  • type - :em/:sync/:block - socket type, asynchronouse on EventMachine, Fibered or blocking TCP

  • pool_size - connection pool size

  • servers - array of server names (host:port) to connect or array of hashes host/port (for Replica Set connection)

  • read_pref - read preference for Replica Set (:primary, :secondary, :primary_preferred, :secondary_preferred), default :primary

  • timeout - client will try to reconnect till timout (in seconds) if connection failed, default 10 seconds



18
19
20
21
22
23
24
25
# File 'lib/monga/client.rb', line 18

def initialize(opts = {})
  @opts = opts
  @opts[:type] ||= :block
  @opts[:timeout] ||= 10

  sanitize_opts!
  create_client
end

Instance Method Details

#get_database(db_name) ⇒ Object Also known as: []

Choose database by it’s name



28
29
30
# File 'lib/monga/client.rb', line 28

def get_database(db_name)
  Monga::Database.new(@client, db_name)
end