NAME
MongoDB::Connection - A connection to a Mongo server
VERSION
version 0.24
SYNOPSIS
The MongoDB::Connection class creates a connection to the MongoDB server.
By default, it connects to a single server running on the local machine listening on the default port:
# connects to localhost:27017
my $connection = MongoDB::Connection->new;
It can connect to a database server running anywhere, though:
my $connection = MongoDB::Connection->new(host => 'example.com', port => 12345);
It can also be used to connect to a replication pair of database servers:
my $connection = MongoDB::Connection->new(left_host => '192.0.2.0', right_host => '192.0.2.1');
If ports aren't given, they default to 27017
.
ATTRIBUTES
host
Hostname to connect to. Defaults to localhost
.
port
Port to use when connecting. Defaults to 27017
.
left_host
Paired connection host to connect to. Can be master or slave.
left_port
Port to use when connecting to left_host. Defaults to 27017
.
right_host
Paired connection host to connect to. Can be master or slave.
right_port
Port to use when connecting to right_host. Defaults to 27017
.
auto_reconnect
Boolean indicating whether or not to reconnect if the connection is interrupted. Defaults to 1
.
auto_connect
Boolean indication whether or not to connect automatically on object construction. Defaults to 1
.
METHODS
connect
$connection->connect;
Connects to the mongo server. Called automatically on object construction if auto_connect
is true.
database_names
my @dbs = $connection->database_names;
Lists all databases on the mongo server.
get_database ($name)
my $database = $connection->get_database('foo');
Returns a MongoDB::Database
instance for database with the given $name
.
find_master
$master = $connection->find_master
Determines which host of a paired connection is master. Does nothing for a non-paired connection. This need never be invoked by a user, it is called automatically by internal functions. Returns 0 if the left host is master, 1 if the right is, -1 if if cannot be determined.
authenticate ($dbname, $username, $password, $is_digest?)
$connection->authenticate('foo', 'username', 'secret');
Attempts to authenticate for use of the $dbname
database with $username
and $password
. Passwords are expected to be cleartext and will be automatically hashed before sending over the wire, unless $is_digest
is true, which will assume you already did the hashing on yourself.
AUTHOR
Kristina Chodorow <kristina@mongodb.org>