Class: Monga::Client
- Inherits:
-
Object
- Object
- Monga::Client
- 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
-
#get_database(db_name) ⇒ Object
(also: #[])
Choose database by it’s name.
-
#initialize(opts = {}) ⇒ Client
constructor
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.
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 |