%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/opti/optisoftcom-new/perl/usr/man/man3/
Upload File :
Create Path :
Current File : /home/opti/optisoftcom-new/perl/usr/man/man3/MongoDB::MongoClient.3pm

.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{
.    if \nF \{
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "MongoDB::MongoClient 3"
.TH MongoDB::MongoClient 3 "2018-11-30" "perl v5.16.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
MongoDB::MongoClient \- A connection to a MongoDB server or multi\-server deployment
.SH "VERSION"
.IX Header "VERSION"
version v2.0.2
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\&    use MongoDB; # also loads MongoDB::MongoClient
\&
\&    # connect to localhost:27017
\&    my $client = MongoDB::MongoClient\->new;
\&
\&    # connect to specific host and port
\&    my $client = MongoDB::MongoClient\->new(
\&        host => "mongodb://mongo.example.com:27017"
\&    );
\&
\&    # connect to a replica set (set name *required*)
\&    my $client = MongoDB::MongoClient\->new(
\&        host => "mongodb://mongo1.example.com,mongo2.example.com",
\&        replica_set_name => \*(Aqmyset\*(Aq,
\&    );
\&
\&    # connect to a replica set with URI (set name *required*)
\&    my $client = MongoDB::MongoClient\->new(
\&        host => "mongodb://mongo1.example.com,mongo2.example.com/?replicaSet=myset",
\&    );
\&
\&    my $db = $client\->get_database("test");
\&    my $coll = $db\->get_collection("people");
\&
\&    $coll\->insert({ name => "John Doe", age => 42 });
\&    my @people = $coll\->find()\->all();
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The \f(CW\*(C`MongoDB::MongoClient\*(C'\fR class represents a client connection to one or
more MongoDB servers.
.PP
By default, it connects to a single server running on the local machine
listening on the default port 27017:
.PP
.Vb 2
\&    # connects to localhost:27017
\&    my $client = MongoDB::MongoClient\->new;
.Ve
.PP
It can connect to a database server running anywhere, though:
.PP
.Vb 1
\&    my $client = MongoDB::MongoClient\->new(host => \*(Aqexample.com:12345\*(Aq);
.Ve
.PP
See the \*(L"host\*(R" attribute for more options for connecting to MongoDB.
.PP
MongoDB can be started in authentication
mode <http://docs.mongodb.org/manual/core/authentication/>, which requires
clients to log in before manipulating data.  By default, MongoDB does not start
in this mode, so no username or password is required to make a fully functional
connection.  To configure the client for authentication, see the
\&\*(L"\s-1AUTHENTICATION\*(R"\s0 section.
.PP
The actual socket connections are lazy and created on demand.  When the client
object goes out of scope, all socket will be closed.  Note that
MongoDB::Database, MongoDB::Collection and related classes could hold a
reference to the client as well.  Only when all references are out of scope
will the sockets be closed.
.SH "ATTRIBUTES"
.IX Header "ATTRIBUTES"
.SS "host"
.IX Subsection "host"
The \f(CW\*(C`host\*(C'\fR attribute specifies either a single server to connect to (as
\&\f(CW\*(C`hostname\*(C'\fR or \f(CW\*(C`hostname:port\*(C'\fR), or else a connection string \s-1URI\s0 with a seed list of one or more servers plus connection options.
.PP
Defaults to the connection string \s-1URI \s0\f(CW\*(C`mongodb://localhost:27017\*(C'\fR.
.PP
For IPv6 support, you must have a recent version of IO::Socket::IP
installed.  This module ships with the Perl core since v5.20.0 and is
available on \s-1CPAN\s0 for older Perls.
.SS "app_name"
.IX Subsection "app_name"
This attribute specifies an application name that should be associated with
this client.  The application name will be communicated to the server as
part of the initial connection handshake, and will appear in
connection-level and operation-level diagnostics on the server generated on
behalf of this client.  This may be set in a connection string with the
\&\f(CW\*(C`appName\*(C'\fR option.
.PP
The default is the empty string, which indicates a lack of an application
name.
.PP
The application name must not exceed 128 bytes.
.SS "auth_mechanism"
.IX Subsection "auth_mechanism"
This attribute determines how the client authenticates with the server.
Valid values are:
.IP "\(bu" 4
\&\s-1NONE\s0
.IP "\(bu" 4
\&\s-1DEFAULT\s0
.IP "\(bu" 4
MONGODB-CR
.IP "\(bu" 4
\&\s-1MONGODB\-X509\s0
.IP "\(bu" 4
\&\s-1GSSAPI\s0
.IP "\(bu" 4
\&\s-1PLAIN\s0
.IP "\(bu" 4
\&\s-1SCRAM\-SHA\-1\s0
.PP
If not specified, then if no username is provided, it defaults to \s-1NONE.\s0
If a username is provided, it is set to \s-1DEFAULT,\s0 which chooses \s-1SCRAM\-SHA\-1\s0 if
available or MONGODB-CR otherwise.
.PP
This may be set in a connection string with the \f(CW\*(C`authMechanism\*(C'\fR option.
.SS "auth_mechanism_properties"
.IX Subsection "auth_mechanism_properties"
This is an optional hash reference of authentication mechanism specific properties.
See \*(L"\s-1AUTHENTICATION\*(R"\s0 for details.
.PP
This may be set in a connection string with the \f(CW\*(C`authMechanismProperties\*(C'\fR
option.  If given, the value must be key/value pairs joined with a \*(L":\*(R".
Multiple pairs must be separated by a comma.  If \*(L": or \*(R"," appear in a key or
value, they must be \s-1URL\s0 encoded.
.SS "bson_codec"
.IX Subsection "bson_codec"
An object that provides the \f(CW\*(C`encode_one\*(C'\fR and \f(CW\*(C`decode_one\*(C'\fR methods, such as
from \s-1BSON\s0.  It may be initialized with a hash reference that will
be coerced into a new \s-1BSON\s0 object.
.PP
If not provided, a \s-1BSON\s0 object with default values will be generated.
.SS "compressors"
.IX Subsection "compressors"
An array reference of compression type names. Currently only \f(CW\*(C`zlib\*(C'\fR
is supported.
.SS "zlib_compression_level"
.IX Subsection "zlib_compression_level"
An integer from \f(CW\*(C`\-1\*(C'\fR to \f(CW9\fR specifying the compression level to use
when \*(L"compression\*(R" is set to \f(CW\*(C`zlib\*(C'\fR.
.PP
\&\fBNote\fR: When the special value \f(CW\*(C`\-1\*(C'\fR is given, the default compression
level will be used.
.SS "connect_timeout_ms"
.IX Subsection "connect_timeout_ms"
This attribute specifies the amount of time in milliseconds to wait for a
new connection to a server.
.PP
The default is 10,000 ms.
.PP
If set to a negative value, connection operations will block indefinitely
until the server replies or until the operating system \s-1TCP/IP\s0 stack gives
up (e.g. if the name can't resolve or there is no process listening on the
target host/port).
.PP
A zero value polls the socket during connection and is thus likely to fail
except when talking to a local process (and perhaps even then).
.PP
This may be set in a connection string with the \f(CW\*(C`connectTimeoutMS\*(C'\fR option.
.SS "db_name"
.IX Subsection "db_name"
Optional.  If an \*(L"auth_mechanism\*(R" requires a database for authentication,
this attribute will be used.  Otherwise, it will be ignored. Defaults to
\&\*(L"admin\*(R".
.PP
This may be provided in the connection string \s-1URI\s0 as
a path between the authority and option parameter sections.  For example, to
authenticate against the \*(L"admin\*(R" database (showing a configuration option only
for illustration):
.PP
.Vb 1
\&    mongodb://localhost/admin?readPreference=primary
.Ve
.SS "heartbeat_frequency_ms"
.IX Subsection "heartbeat_frequency_ms"
The time in milliseconds (non-negative) between scans of all servers to
check if they are up and update their latency.  Defaults to 60,000 ms.
.PP
This may be set in a connection string with the \f(CW\*(C`heartbeatFrequencyMS\*(C'\fR option.
.SS "j"
.IX Subsection "j"
If true, the client will block until write operations have been committed to the
server's journal. Prior to MongoDB 2.6, this option was ignored if the server was
running without journaling. Starting with MongoDB 2.6, write operations will fail
if this option is used when the server is running without journaling.
.PP
This may be set in a connection string with the \f(CW\*(C`journal\*(C'\fR option as the
strings 'true' or 'false'.
.SS "local_threshold_ms"
.IX Subsection "local_threshold_ms"
The width of the 'latency window': when choosing between multiple suitable
servers for an operation, the acceptable delta in milliseconds
(non-negative) between shortest and longest average round-trip times.
Servers within the latency window are selected randomly.
.PP
Set this to \*(L"0\*(R" to always select the server with the shortest average round
trip time.  Set this to a very high value to always randomly choose any known
server.
.PP
Defaults to 15 ms.
.PP
See \*(L"\s-1SERVER SELECTION\*(R"\s0 for more details.
.PP
This may be set in a connection string with the \f(CW\*(C`localThresholdMS\*(C'\fR option.
.SS "max_staleness_seconds"
.IX Subsection "max_staleness_seconds"
The \f(CW\*(C`max_staleness_seconds\*(C'\fR parameter represents the maximum replication lag in
seconds (wall clock time) that a secondary can suffer and still be
eligible for reads. The default is \-1, which disables staleness checks.
Otherwise, it must be a positive integer.
.PP
\&\fBNote\fR: this will only be used for server versions 3.4 or greater, as that
was when support for staleness tracking was added.
.PP
If the read preference mode is 'primary', then \f(CW\*(C`max_staleness_seconds\*(C'\fR must not
be supplied.
.PP
The \f(CW\*(C`max_staleness_seconds\*(C'\fR must be at least the \f(CW\*(C`heartbeat_frequency_ms\*(C'\fR
plus 10 seconds (which is how often the server makes idle writes to the
oplog).
.PP
This may be set in a connection string with the \f(CW\*(C`maxStalenessSeconds\*(C'\fR option.
.SS "max_time_ms"
.IX Subsection "max_time_ms"
Specifies the maximum amount of time in (non-negative) milliseconds that the
server should use for working on a database command.  Defaults to 0, which disables
this feature.  Make sure this value is shorter than \f(CW\*(C`socket_timeout_ms\*(C'\fR.
.PP
\&\fBNote\fR: this will only be used for server versions 2.6 or greater, as that
was when the \f(CW$maxTimeMS\fR meta-operator was introduced.
.PP
You are \fBstrongly\fR encouraged to set this variable if you know your
environment has MongoDB 2.6 or later, as getting a definitive error response
from the server is vastly preferred over a getting a network socket timeout.
.PP
This may be set in a connection string with the \f(CW\*(C`maxTimeMS\*(C'\fR option.
.SS "monitoring_callback"
.IX Subsection "monitoring_callback"
Specifies a code reference used to receive monitoring events.  See
MongoDB::Monitoring for more details.
.SS "password"
.IX Subsection "password"
If an \*(L"auth_mechanism\*(R" requires a password, this attribute will be
used.  Otherwise, it will be ignored.
.PP
This may be provided in the connection string \s-1URI\s0 as
a \f(CW\*(C`username:password\*(C'\fR pair in the leading portion of the authority section
before a \f(CW\*(C`@\*(C'\fR character.  For example, to authenticate as user \*(L"mulder\*(R" with
password \*(L"trustno1\*(R":
.PP
.Vb 1
\&    mongodb://mulder:trustno1@localhost
.Ve
.PP
If the username or password have a \*(L":\*(R" or \*(L"@\*(R" in it, they must be \s-1URL\s0 encoded.
An empty password still requires a \*(L":\*(R" character.
.SS "port"
.IX Subsection "port"
If a network port is not specified as part of the \f(CW\*(C`host\*(C'\fR attribute, this
attribute provides the port to use.  It defaults to 27107.
.SS "read_pref_mode"
.IX Subsection "read_pref_mode"
The read preference mode determines which server types are candidates
for a read operation.  Valid values are:
.IP "\(bu" 4
primary
.IP "\(bu" 4
primaryPreferred
.IP "\(bu" 4
secondary
.IP "\(bu" 4
secondaryPreferred
.IP "\(bu" 4
nearest
.PP
For core documentation on read preference see
<http://docs.mongodb.org/manual/core/read\-preference/>.
.PP
This may be set in a connection string with the \f(CW\*(C`readPreference\*(C'\fR option.
.SS "read_pref_tag_sets"
.IX Subsection "read_pref_tag_sets"
The \f(CW\*(C`read_pref_tag_sets\*(C'\fR parameter is an ordered list of tag sets used to
restrict the eligibility of servers, such as for data center awareness.  It
must be an array reference of hash references.
.PP
The application of \f(CW\*(C`read_pref_tag_sets\*(C'\fR varies depending on the
\&\f(CW\*(C`read_pref_mode\*(C'\fR parameter.  If the \f(CW\*(C`read_pref_mode\*(C'\fR is 'primary', then
\&\f(CW\*(C`read_pref_tag_sets\*(C'\fR must not be supplied.
.PP
For core documentation on read preference see
<http://docs.mongodb.org/manual/core/read\-preference/>.
.PP
This may be set in a connection string with the \f(CW\*(C`readPreferenceTags\*(C'\fR option.
If given, the value must be key/value pairs joined with a \*(L":\*(R".  Multiple pairs
must be separated by a comma.  If \*(L": or \*(R"," appear in a key or value, they must
be \s-1URL\s0 encoded.  The \f(CW\*(C`readPreferenceTags\*(C'\fR option may appear more than once, in
which case each document will be added to the tag set list.
.SS "replica_set_name"
.IX Subsection "replica_set_name"
Specifies the replica set name to connect to.  If this string is non-empty,
then the topology is treated as a replica set and all server replica set
names must match this or they will be removed from the topology.
.PP
This may be set in a connection string with the \f(CW\*(C`replicaSet\*(C'\fR option.
.SS "server_selection_timeout_ms"
.IX Subsection "server_selection_timeout_ms"
This attribute specifies the amount of time in milliseconds to wait for a
suitable server to be available for a read or write operation.  If no
server is available within this time period, an exception will be thrown.
.PP
The default is 30,000 ms.
.PP
See \*(L"\s-1SERVER SELECTION\*(R"\s0 for more details.
.PP
This may be set in a connection string with the \f(CW\*(C`serverSelectionTimeoutMS\*(C'\fR
option.
.SS "server_selection_try_once"
.IX Subsection "server_selection_try_once"
This attribute controls whether the client will make only a single attempt
to find a suitable server for a read or write operation.  The default is true.
.PP
When true, the client will \fBnot\fR use the \f(CW\*(C`server_selection_timeout_ms\*(C'\fR.
Instead, if the topology information is stale and needs to be checked or
if no suitable server is available, the client will make a single
scan of all known servers to try to find a suitable one.
.PP
When false, the client will continually scan known servers until a suitable
server is found or the \f(CW\*(C`serverSelectionTimeoutMS\*(C'\fR is reached.
.PP
See \*(L"\s-1SERVER SELECTION\*(R"\s0 for more details.
.PP
This may be set in a connection string with the \f(CW\*(C`serverSelectionTryOnce\*(C'\fR
option.
.SS "socket_check_interval_ms"
.IX Subsection "socket_check_interval_ms"
If a socket to a server has not been used in this many milliseconds, an
\&\f(CW\*(C`ismaster\*(C'\fR command will be issued to check the status of the server before
issuing any reads or writes. Must be non-negative.
.PP
The default is 5,000 ms.
.PP
This may be set in a connection string with the \f(CW\*(C`socketCheckIntervalMS\*(C'\fR
option.
.SS "socket_timeout_ms"
.IX Subsection "socket_timeout_ms"
This attribute specifies the amount of time in milliseconds to wait for a
reply from the server before issuing a network exception.
.PP
The default is 30,000 ms.
.PP
If set to a negative value, socket operations will block indefinitely
until the server replies or until the operating system \s-1TCP/IP\s0 stack
gives up.
.PP
A zero value polls the socket for available data and is thus likely to fail
except when talking to a local process (and perhaps even then).
.PP
This may be set in a connection string with the \f(CW\*(C`socketTimeoutMS\*(C'\fR option.
.SS "ssl"
.IX Subsection "ssl"
.Vb 2
\&    ssl => 1
\&    ssl => \e%ssl_options
.Ve
.PP
This tells the driver that you are connecting to an \s-1SSL\s0 mongodb instance.
.PP
You must have IO::Socket::SSL 1.42+ and Net::SSLeay 1.49+ installed for
\&\s-1SSL\s0 support.
.PP
The \f(CW\*(C`ssl\*(C'\fR attribute takes either a boolean value or a hash reference of
options to pass to IO::Socket::SSL.  For example, to set a \s-1CA\s0 file to validate
the server certificate and set a client certificate for the server to validate,
you could set the attribute like this:
.PP
.Vb 4
\&    ssl => {
\&        SSL_ca_file   => "/path/to/ca.pem",
\&        SSL_cert_file => "/path/to/client.pem",
\&    }
.Ve
.PP
If \f(CW\*(C`SSL_ca_file\*(C'\fR is not provided, server certificates are verified against a
default list of CAs, either Mozilla::CA or an operating-system-specific
default \s-1CA\s0 file.  To disable verification, you can use
\&\f(CW\*(C`SSL_verify_mode => 0x00\*(C'\fR.
.PP
\&\fBYou are strongly encouraged to use your own \s-1CA\s0 file for increased security\fR.
.PP
Server hostnames are also validated against the \s-1CN\s0 name in the server
certificate using \f(CW\*(C`SSL_verifycn_scheme => \*(Aqhttp\*(Aq\*(C'\fR.  You can use the
scheme 'none' to disable this check.
.PP
\&\fBDisabling certificate or hostname verification is a security risk and is not
recommended\fR.
.PP
This may be set to the string 'true' or 'false' in a connection string with the
\&\f(CW\*(C`ssl\*(C'\fR option, which will enable ssl with default configuration.  (A future
version of the driver may support customizing ssl via the connection string.)
.SS "username"
.IX Subsection "username"
Optional username for this client connection.  If this field is set, the client
will attempt to authenticate when connecting to servers.  Depending on the
\&\*(L"auth_mechanism\*(R", the \*(L"password\*(R" field or other attributes will need to be
set for authentication to succeed.
.PP
This may be provided in the connection string \s-1URI\s0 as
a \f(CW\*(C`username:password\*(C'\fR pair in the leading portion of the authority section
before a \f(CW\*(C`@\*(C'\fR character.  For example, to authenticate as user \*(L"mulder\*(R" with
password \*(L"trustno1\*(R":
.PP
.Vb 1
\&    mongodb://mulder:trustno1@localhost
.Ve
.PP
If the username or password have a \*(L":\*(R" or \*(L"@\*(R" in it, they must be \s-1URL\s0 encoded.
An empty password still requires a \*(L":\*(R" character.
.SS "w"
.IX Subsection "w"
The client \fIwrite concern\fR.
.IP "\(bu" 4
\&\f(CW0\fR Unacknowledged. MongoClient will \fB\s-1NOT\s0\fR wait for an acknowledgment that
the server has received and processed the request. Older documentation may refer
to this as \*(L"fire-and-forget\*(R" mode.  This option is not recommended.
.IP "\(bu" 4
\&\f(CW1\fR Acknowledged. This is the default. MongoClient will wait until the
primary MongoDB acknowledges the write.
.IP "\(bu" 4
\&\f(CW2\fR Replica acknowledged. MongoClient will wait until at least two
replicas (primary and one secondary) acknowledge the write. You can set a higher
number for more replicas.
.IP "\(bu" 4
\&\f(CW\*(C`all\*(C'\fR All replicas acknowledged.
.IP "\(bu" 4
\&\f(CW\*(C`majority\*(C'\fR A majority of replicas acknowledged.
.PP
In MongoDB v2.0+, you can \*(L"tag\*(R" replica members. With \*(L"tagging\*(R" you can
specify a custom write concern For more information see Data Center
Awareness <http://docs.mongodb.org/manual/data-center-awareness/>
.PP
This may be set in a connection string with the \f(CW\*(C`w\*(C'\fR option.
.SS "wtimeout"
.IX Subsection "wtimeout"
The number of milliseconds an operation should wait for \f(CW\*(C`w\*(C'\fR secondaries to
replicate it.
.PP
Defaults to 1000 (1 second).
.PP
See \f(CW\*(C`w\*(C'\fR above for more information.
.PP
This may be set in a connection string with the \f(CW\*(C`wTimeoutMS\*(C'\fR option.
.SS "read_concern_level"
.IX Subsection "read_concern_level"
The read concern level determines the consistency level required
of data being read.
.PP
The default level is \f(CW\*(C`undef\*(C'\fR, which means the server will use its configured
default.
.PP
If the level is set to \*(L"local\*(R", reads will return the latest data a server has
locally.
.PP
Additional levels are storage engine specific.  See Read
Concern <http://docs.mongodb.org/manual/search/?query=readConcern> in the MongoDB
documentation for more details.
.PP
This may be set in a connection string with the the \f(CW\*(C`readConcernLevel\*(C'\fR option.
.SS "retry_writes"
.IX Subsection "retry_writes"
Whether the client should use retryable writes for supported commands. The
default value is false, which means that no write commands will be retried.
.PP
If this is set to a true value, then commands which support retryable writes
will be retried on certain errors, such as \f(CW\*(C`not master\*(C'\fR and \f(CW\*(C`node is
recovering\*(C'\fR errors.
.PP
This may be set in a connection string with the \f(CW\*(C`retryWrites\*(C'\fR option.
.PP
Note that this is only supported on MongoDB > 3.6 in Replica Set or Shard
Clusters, and will be ignored on other deployments.
.PP
Unacknowledged write operations also do not support retryable writes, even when
retry_writes has been enabled.
.PP
The supported single statement write operations are currently as follows:
.IP "\(bu" 4
\&\f(CW\*(C`insert_one\*(C'\fR
.IP "\(bu" 4
\&\f(CW\*(C`update_one\*(C'\fR
.IP "\(bu" 4
\&\f(CW\*(C`replace_one\*(C'\fR
.IP "\(bu" 4
\&\f(CW\*(C`delete_one\*(C'\fR
.IP "\(bu" 4
\&\f(CW\*(C`find_one_and_delete\*(C'\fR
.IP "\(bu" 4
\&\f(CW\*(C`find_one_and_replace\*(C'\fR
.IP "\(bu" 4
\&\f(CW\*(C`find_one_and_update\*(C'\fR
.PP
The supported multi statement write operations are as follows:
.IP "\(bu" 4
\&\f(CW\*(C`insert_many\*(C'\fR
.IP "\(bu" 4
\&\f(CW\*(C`bulk_write\*(C'\fR
.PP
The multi statement operations may be ether ordered or unordered. Note that for
\&\f(CW\*(C`bulk_write\*(C'\fR operations, the request may not include update_many or
delete_many operations.
.SH "METHODS"
.IX Header "METHODS"
.SS "read_preference"
.IX Subsection "read_preference"
Returns a MongoDB::ReadPreference object constructed from
\&\*(L"read_pref_mode\*(R" and \*(L"read_pref_tag_sets\*(R"
.PP
\&\fBThe use of \f(CB\*(C`read_preference\*(C'\fB as a mutator has been removed.\fR  Read
preference is read-only.  If you need a different read preference for
a database or collection, you can specify that in \f(CW\*(C`get_database\*(C'\fR or
\&\f(CW\*(C`get_collection\*(C'\fR.
.SS "write_concern"
.IX Subsection "write_concern"
Returns a MongoDB::WriteConcern object constructed from \*(L"w\*(R", \*(L"write_concern\*(R"
and \*(L"j\*(R".
.SS "read_concern"
.IX Subsection "read_concern"
Returns a MongoDB::ReadConcern object constructed from
\&\*(L"read_concern_level\*(R".
.SS "topology_type"
.IX Subsection "topology_type"
Returns an enumerated topology type.  If the \*(L"replica_set_name\*(R" is set,
the value will be either 'ReplicaSetWithPrimary' or 'ReplicaSetNoPrimary'
(if the primary is down or not yet discovered).  Without
\&\*(L"replica_set_name\*(R", if there is more than one server in the list of
hosts, the type will be 'Sharded'.
.PP
With only a single host and no replica set name, the topology type will
start as 'Direct' until the server is contacted the first time, after which
the type will be 'Sharded' for a mongos or 'Single' for standalone server
or direct connection to a replica set member.
.SS "connect"
.IX Subsection "connect"
.Vb 1
\&    $client\->connect;
.Ve
.PP
Calling this method is unnecessary, as connections are established
automatically as needed.  It is kept for backwards compatibility.  Calling it
will check all servers in the deployment which ensures a connection to any
that are available.
.PP
See \*(L"reconnect\*(R" for a method that is useful when using forks or threads.
.SS "disconnect"
.IX Subsection "disconnect"
.Vb 1
\&    $client\->disconnect;
.Ve
.PP
Drops all connections to servers.
.SS "reconnect"
.IX Subsection "reconnect"
.Vb 1
\&    $client\->reconnect;
.Ve
.PP
This method closes all connections to the server, as if \*(L"disconnect\*(R" were
called, and then immediately reconnects.  It also clears the session
cache.  Use this after forking or spawning off a new thread.
.SS "topology_status"
.IX Subsection "topology_status"
.Vb 2
\&    $client\->topology_status;
\&    $client\->topology_status( refresh => 1 );
.Ve
.PP
Returns a hash reference with server topology information like this:
.PP
.Vb 10
\&    {
\&        \*(Aqtopology_type\*(Aq => \*(AqReplicaSetWithPrimary\*(Aq
\&        \*(Aqreplica_set_name\*(Aq => \*(Aqfoo\*(Aq,
\&        \*(Aqlast_scan_time\*(Aq   => \*(Aq1433766895.183241\*(Aq,
\&        \*(Aqservers\*(Aq          => [
\&            {
\&                \*(Aqaddress\*(Aq     => \*(Aqlocalhost:50003\*(Aq,
\&                \*(Aqewma_rtt_ms\*(Aq => \*(Aq0.223462326\*(Aq,
\&                \*(Aqtype\*(Aq        => \*(AqRSSecondary\*(Aq
\&            },
\&            {
\&                \*(Aqaddress\*(Aq     => \*(Aqlocalhost:50437\*(Aq,
\&                \*(Aqewma_rtt_ms\*(Aq => \*(Aq0.268435456\*(Aq,
\&                \*(Aqtype\*(Aq        => \*(AqRSArbiter\*(Aq
\&            },
\&            {
\&                \*(Aqaddress\*(Aq     => \*(Aqlocalhost:50829\*(Aq,
\&                \*(Aqewma_rtt_ms\*(Aq => \*(Aq0.737782272\*(Aq,
\&                \*(Aqtype\*(Aq        => \*(AqRSPrimary\*(Aq
\&            }
\&        },
\&    }
.Ve
.PP
If the 'refresh' argument is true, then the topology will be scanned
to update server data before returning the hash reference.
.SS "start_session"
.IX Subsection "start_session"
.Vb 2
\&    $client\->start_session;
\&    $client\->start_session( $options );
.Ve
.PP
Returns a new MongoDB::ClientSession with the supplied options.
.PP
will throw a \f(CW\*(C`MongoDB::ConfigurationError\*(C'\fR if sessions are not supported by
the connected MongoDB deployment.
.PP
the options hash is an optional hash which can have the following keys:
.IP "\(bu" 4
\&\f(CW\*(C`causalConsistency\*(C'\fR \- Enable Causally Consistent reads for this session. Defaults to true.
.PP
for more information see \*(L"options\*(R" in MongoDB::ClientSession.
.SS "list_databases"
.IX Subsection "list_databases"
.Vb 2
\&    # get all information on all databases
\&    my @dbs = $client\->list_databases;
\&
\&    # get only the foo databases
\&    my @foo_dbs = $client\->list_databases({ filter => { name => qr/^foo/ } });
.Ve
.PP
Lists all databases with information on each database. Supports filtering by
any of the output fields under the \f(CW\*(C`filter\*(C'\fR argument, such as:
.IP "\(bu" 4
\&\f(CW\*(C`name\*(C'\fR
.IP "\(bu" 4
\&\f(CW\*(C`sizeOnDisk\*(C'\fR
.IP "\(bu" 4
\&\f(CW\*(C`empty\*(C'\fR
.IP "\(bu" 4
\&\f(CW\*(C`shards\*(C'\fR
.SS "database_names"
.IX Subsection "database_names"
.Vb 1
\&    my @dbs = $client\->database_names;
\&
\&    # get only the foo database names
\&    my @foo_dbs = $client\->database_names({ filter => { name => qr/^foo/ } });
.Ve
.PP
List of all database names on the MongoDB server. Supports filters in the same
way as \*(L"list_databases\*(R".
.SS "get_database, db"
.IX Subsection "get_database, db"
.Vb 3
\&    my $database = $client\->get_database(\*(Aqfoo\*(Aq);
\&    my $database = $client\->get_database(\*(Aqfoo\*(Aq, $options);
\&    my $database = $client\->db(\*(Aqfoo\*(Aq, $options);
.Ve
.PP
Returns a MongoDB::Database instance for the database with the given
\&\f(CW$name\fR.
.PP
It takes an optional hash reference of options that are passed to the
MongoDB::Database constructor.
.PP
The \f(CW\*(C`db\*(C'\fR method is an alias for \f(CW\*(C`get_database\*(C'\fR.
.SS "get_namespace, ns"
.IX Subsection "get_namespace, ns"
.Vb 3
\&    my $collection = $client\->get_namespace(\*(Aqtest.foo\*(Aq);
\&    my $collection = $client\->get_namespace(\*(Aqtest.foo\*(Aq, $options);
\&    my $collection = $client\->ns(\*(Aqtest.foo\*(Aq, $options);
.Ve
.PP
Returns a MongoDB::Collection instance for the given namespace.
The namespace has both the database name and the collection name
separated with a dot character.
.PP
This is a quick way to get a collection object if you don't need
the database object separately.
.PP
It takes an optional hash reference of options that are passed to the
MongoDB::Collection constructor.  The intermediate MongoDB::Database
object will be created with default options.
.PP
The \f(CW\*(C`ns\*(C'\fR method is an alias for \f(CW\*(C`get_namespace\*(C'\fR.
.SS "fsync(\e%args)"
.IX Subsection "fsync(%args)"
.Vb 1
\&    $client\->fsync();
.Ve
.PP
A function that will forces the server to flush all pending writes to the storage layer.
.PP
The fsync operation is synchronous by default, to run fsync asynchronously, use the following form:
.PP
.Vb 1
\&    $client\->fsync({async => 1});
.Ve
.PP
The primary use of fsync is to lock the database during backup operations. This will flush all data to the data storage layer and block all write operations until you unlock the database. Note: you can still read while the database is locked.
.PP
.Vb 1
\&    $conn\->fsync({lock => 1});
.Ve
.SS "fsync_unlock"
.IX Subsection "fsync_unlock"
.Vb 1
\&    $conn\->fsync_unlock();
.Ve
.PP
Unlocks a database server to allow writes and reverses the operation of a \f(CW$conn\fR\->fsync({lock => 1}); operation.
.SS "watch"
.IX Subsection "watch"
Watches for changes on the cluster.
.PP
Perform an aggregation with an implicit initial \f(CW$changeStream\fR stage
and returns a MongoDB::ChangeStream result which can be used to
iterate over the changes in the cluster. This functionality is
available since MongoDB 4.0.
.PP
.Vb 3
\&    my $stream = $client\->watch();
\&    my $stream = $client\->watch( \e@pipeline );
\&    my $stream = $client\->watch( \e@pipeline, \e%options );
\&
\&    while (1) {
\&
\&        # This inner loop will only run until no more changes are
\&        # available.
\&        while (my $change = $stream\->next) {
\&            # process $change
\&        }
\&    }
.Ve
.PP
The returned stream will not block forever waiting for changes. If you
want to respond to changes over a longer time use \f(CW\*(C`maxAwaitTimeMS\*(C'\fR and
regularly call \f(CW\*(C`next\*(C'\fR in a loop.
.PP
See \*(L"watch\*(R" in MongoDB::Collection for details on usage and available
options.
.SH "DEPLOYMENT TOPOLOGY"
.IX Header "DEPLOYMENT TOPOLOGY"
MongoDB can operate as a single server or as a distributed system.  One or more
servers that collectively provide access to a single logical set of MongoDB
databases are referred to as a \*(L"deployment\*(R".
.PP
There are three types of deployments:
.IP "\(bu" 4
Single server X a stand-alone mongod database
.IP "\(bu" 4
Replica set X a set of mongod databases with data replication and fail-over capability
.IP "\(bu" 4
Sharded cluster X\ a distributed deployment that spreads data across one or more shards, each of which can be a replica set.  Clients communicate with a mongos process that routes operations to the correct share.
.PP
The state of a deployment, including its type, which servers are members, the
server types of members and the round-trip network latency to members is
referred to as the \*(L"topology\*(R" of the deployment.
.PP
To the greatest extent possible, the MongoDB driver abstracts away the details
of communicating with different deployment types.  It determines the deployment
topology through a combination of the connection string, configuration options
and direct discovery communicating with servers in the deployment.
.SH "CONNECTION STRING URI"
.IX Header "CONNECTION STRING URI"
MongoDB uses a pseudo-URI connection string to specify one or more servers to
connect to, along with configuration options.
.PP
\&\s-1NOTE:\s0 any non-printable \s-1ASCII\s0 characters should be \s-1UTF\-8\s0 encoded and converted
URL-escaped characters.
.PP
To connect to more than one database server, provide host or host:port pairs
as a comma separated list:
.PP
.Vb 1
\&    mongodb://host1[:port1][,host2[:port2],...[,hostN[:portN]]]
.Ve
.PP
This list is referred to as the \*(L"seed list\*(R".  An arbitrary number of hosts can
be specified.  If a port is not specified for a given host, it will default to
27017.
.PP
If multiple hosts are given in the seed list or discovered by talking to
servers in the seed list, they must all be replica set members or must all be
mongos servers for a sharded cluster.
.PP
A replica set \fB\s-1MUST\s0\fR have the \f(CW\*(C`replicaSet\*(C'\fR option set to the replica set
name.
.PP
If there is only single host in the seed list and \f(CW\*(C`replicaSet\*(C'\fR is not
provided, the deployment is treated as a single server deployment and all
reads and writes will be sent to that host.
.PP
Providing a replica set member as a single host without the set name is the
way to get a \*(L"direct connection\*(R" for carrying out administrative activities
on that server.
.PP
The connection string may also have a username and password:
.PP
.Vb 1
\&    mongodb://username:password@host1:port1,host2:port2
.Ve
.PP
The username and password must be URL-escaped.
.PP
A optional database name for authentication may be given:
.PP
.Vb 1
\&    mongodb://username:password@host1:port1,host2:port2/my_database
.Ve
.PP
Finally, connection string options may be given as \s-1URI\s0 attribute pairs in a query
string:
.PP
.Vb 2
\&    mongodb://host1:port1,host2:port2/?ssl=1&wtimeoutMS=1000
\&    mongodb://username:password@host1:port1,host2:port2/my_database?ssl=1&wtimeoutMS=1000
.Ve
.PP
The currently supported connection string options are:
.Sp
.RS 4
*appName
*authMechanism
*authMechanism.SERVICE_NAME
*compressors
*connectTimeoutMS
*journal
*readPreference
*readPreferenceTags
*replicaSet
*ssl
*w
*wtimeoutMS
*zlibCompressionLevel
.RE
.PP
See the official MongoDB documentation on connection strings for more on the \s-1URI\s0
format and connection string options:
<http://docs.mongodb.org/manual/reference/connection\-string/>.
.SH "SERVER SELECTION"
.IX Header "SERVER SELECTION"
For a single server deployment or a direct connection to a mongod or
mongos, all reads and writes and sent to that server.  Any read-preference
is ignored.
.PP
When connected to a deployment with multiple servers, such as a replica set
or sharded cluster, the driver chooses a server for operations based on the
type of operation (read or write), the types of servers available and a
read preference.
.PP
For a replica set deployment, writes are sent to the primary (if available)
and reads are sent to a server based on the \*(L"read_preference\*(R" attribute,
which defaults to sending reads to the primary.  See
MongoDB::ReadPreference for more.
.PP
For a sharded cluster reads and writes are distributed across mongos
servers in the seed list.  Any read preference is passed through to the
mongos and used by it when executing reads against shards.
.PP
If multiple servers can service an operation (e.g. multiple mongos servers,
or multiple replica set members), one is chosen at random from within the
\&\*(L"latency window\*(R".  The server with the shortest average round-trip time
(\s-1RTT\s0) is always in the window.  Any servers with an average round-trip time
less than or equal to the shortest \s-1RTT\s0 plus the \*(L"local_threshold_ms\*(R" are
also in the latency window.
.PP
If a suitable server is not immediately available, what happens next
depends on the \*(L"server_selection_try_once\*(R" option.
.PP
If that option is true, a single topology scan will be performed.
Afterwards if a suitable server is available, it will be returned;
otherwise, an exception is thrown.
.PP
If that option is false, the driver will do topology scans repeatedly
looking for a suitable server.  When more than
\&\*(L"server_selection_timeout_ms\*(R" milliseconds have elapsed since the start
of server selection without a suitable server being found, an exception is
thrown.
.PP
\&\fBNote\fR: the actual maximum wait time for server selection could be as long
\&\f(CW\*(C`server_selection_timeout_ms\*(C'\fR plus the amount of time required to do a
topology scan.
.SH "SERVER MONITORING AND FAILOVER"
.IX Header "SERVER MONITORING AND FAILOVER"
When the client first needs to find a server for a database operation, all
servers from the \*(L"host\*(R" attribute are scanned to determine which servers to
monitor.  If the deployment is a replica set, additional hosts may be
discovered in this process.  Invalid hosts are dropped.
.PP
After the initial scan, whenever the servers have not been checked in
\&\*(L"heartbeat_frequency_ms\*(R" milliseconds, the scan will be repeated.  This
amortizes monitoring time over many of operations.  Additionally, if a
socket has been idle for a while, it will be checked before being used for
an operation.
.PP
If a server operation fails because of a \*(L"not master\*(R" or \*(L"node is
recovering\*(R" error, or if there is a network error or timeout, then the
server is flagged as unavailable and exception will be thrown.  See
MongoDB::Errors for exception types.
.PP
If the error is caught and handled, the next operation will rescan all
servers immediately to update its view of the topology.  The driver can
continue to function as long as servers are suitable per \*(L"\s-1SERVER
SELECTION\*(R"\s0.
.PP
When catching an exception, users must determine whether or not their
application should retry an operation based on the specific operation
attempted and other use-case-specific considerations.  For automating
retries despite exceptions, consider using the Try::Tiny::Retry module.
.SH "TRANSPORT LAYER SECURITY"
.IX Header "TRANSPORT LAYER SECURITY"
\&\fBWarning\fR: industry best practices, and some regulations, require the use
of \s-1TLS 1.1\s0 or newer.
.PP
Some operating systems or versions may not provide an OpenSSL version new
enough to support the latest \s-1TLS\s0 protocols.  If your OpenSSL library
version number is less than 1.0.1, then support for \s-1TLS 1.1\s0 or newer is not
available. Contact your operating system vendor for a solution or upgrade
to a newer operating system distribution.
.PP
See also the documentation for Net::SSLeay for details on installing and
compiling against OpenSSL.
.PP
\&\s-1TLS\s0 connections in the driver rely on the default settings provided by
IO::Socket::SSL, but allow you to pass custom configuration to it.
Please read its documentation carefully to see how to control your \s-1TLS\s0
configuration.
.SH "AUTHENTICATION"
.IX Header "AUTHENTICATION"
The MongoDB server provides several authentication mechanisms, though some
are only available in the Enterprise edition.
.PP
MongoDB client authentication is controlled via the \*(L"auth_mechanism\*(R"
attribute, which takes one of the following values:
.PP
\&\fB\s-1NOTE\s0\fR: MONGODB-CR was deprecated with the release of MongoDB 3.6 and
is no longer supported by MongoDB 4.0.
.IP "\(bu" 4
MONGODB-CR \*(-- legacy username-password challenge-response (< 4.0)
.IP "\(bu" 4
\&\s-1SCRAM\-SHA\-1\s0 \*(-- secure username-password challenge-response (3.0+)
.IP "\(bu" 4
\&\s-1MONGODB\-X509\s0 \*(-- \s-1SSL\s0 client certificate authentication (2.6+)
.IP "\(bu" 4
\&\s-1PLAIN\s0 \*(-- \s-1LDAP\s0 authentication via \s-1SASL PLAIN \s0(Enterprise only)
.IP "\(bu" 4
\&\s-1GSSAPI\s0 \*(-- Kerberos authentication (Enterprise only)
.PP
The mechanism to use depends on the authentication configuration of the
server.  See the core documentation on authentication:
<http://docs.mongodb.org/manual/core/access\-control/>.
.PP
Usage information for each mechanism is given below.
.SS "MONGODB-CR and \s-1SCRAM\-SHA\-1 \s0(for username/password)"
.IX Subsection "MONGODB-CR and SCRAM-SHA-1 (for username/password)"
These mechanisms require a username and password, given either as
constructor attributes or in the \f(CW\*(C`host\*(C'\fR connection string.
.PP
If a username is provided and an authentication mechanism is not specified,
the client will use \s-1SCRAM\-SHA\-1\s0 for version 3.0 or later servers and will
fall back to MONGODB-CR for older servers.
.PP
.Vb 5
\&    my $mc = MongoDB::MongoClient\->new(
\&        host => "mongodb://mongo.example.com/",
\&        username => "johndoe",
\&        password => "trustno1",
\&    );
\&
\&    my $mc = MongoDB::MongoClient\->new(
\&        host => "mongodb://johndoe:trustno1@mongo.example.com/",
\&    );
.Ve
.PP
Usernames and passwords will be \s-1UTF\-8\s0 encoded before use.  The password is
never sent over the wire \*(-- only a secure digest is used.  The \s-1SCRAM\-SHA\-1\s0
mechanism is the Salted Challenge Response Authentication Mechanism
defined in \s-1RFC 5802\s0 <http://tools.ietf.org/html/rfc5802>.
.PP
The default database for authentication is 'admin'.  If another database
name should be used, specify it with the \f(CW\*(C`db_name\*(C'\fR attribute or via the
connection string.
.PP
.Vb 1
\&    db_name => auth_db
\&
\&    mongodb://johndoe:trustno1@mongo.example.com/auth_db
.Ve
.SS "\s-1MONGODB\-X509 \s0(for \s-1SSL\s0 client certificate)"
.IX Subsection "MONGODB-X509 (for SSL client certificate)"
X509 authentication requires \s-1SSL\s0 support (IO::Socket::SSL), requires
that a client certificate be configured in the ssl parameters, and requires
specifying the \*(L"\s-1MONGODB\-X509\*(R"\s0 authentication mechanism.
.PP
.Vb 8
\&    my $mc = MongoDB::MongoClient\->new(
\&        host => "mongodb://sslmongo.example.com/",
\&        ssl => {
\&            SSL_ca_file   => "certs/ca.pem",
\&            SSL_cert_file => "certs/client.pem",
\&        },
\&        auth_mechanism => "MONGODB\-X509",
\&    );
.Ve
.PP
\&\fBNote\fR: Since MongoDB Perl driver v1.8.0, you no longer need to specify a
\&\f(CW\*(C`username\*(C'\fR parameter for X509 authentication; the username will be
extracted automatically from the certificate.
.SS "\s-1PLAIN \s0(for \s-1LDAP\s0)"
.IX Subsection "PLAIN (for LDAP)"
This mechanism requires a username and password, which will be \s-1UTF\-8\s0
encoded before use.  The \f(CW\*(C`auth_mechanism\*(C'\fR parameter must be given as a
constructor attribute or in the \f(CW\*(C`host\*(C'\fR connection string:
.PP
.Vb 6
\&    my $mc = MongoDB::MongoClient\->new(
\&        host => "mongodb://mongo.example.com/",
\&        username => "johndoe",
\&        password => "trustno1",
\&        auth_mechanism => "PLAIN",
\&    );
\&
\&    my $mc = MongoDB::MongoClient\->new(
\&        host => "mongodb://johndoe:trustno1@mongo.example.com/authMechanism=PLAIN",
\&    );
.Ve
.SS "\s-1GSSAPI \s0(for Kerberos)"
.IX Subsection "GSSAPI (for Kerberos)"
Kerberos authentication requires the \s-1CPAN\s0 module Authen::SASL and a
GSSAPI-capable backend.
.PP
On Debian systems, Authen::SASL may be available as
\&\f(CW\*(C`libauthen\-sasl\-perl\*(C'\fR; on \s-1RHEL\s0 systems, it may be available as
\&\f(CW\*(C`perl\-Authen\-SASL\*(C'\fR.
.PP
The Authen::SASL::Perl backend comes with Authen::SASL and requires
the \s-1GSSAPI\s0 \s-1CPAN\s0 module for \s-1GSSAPI\s0 support.  On Debian systems, this may
be available as \f(CW\*(C`libgssapi\-perl\*(C'\fR; on \s-1RHEL\s0 systems, it may be available as
\&\f(CW\*(C`perl\-GSSAPI\*(C'\fR.
.PP
Installing the \s-1GSSAPI\s0 module from \s-1CPAN\s0 rather than an \s-1OS\s0 package
requires \f(CW\*(C`libkrb5\*(C'\fR and the \f(CW\*(C`krb5\-config\*(C'\fR utility (available for
Debian/RHEL systems in the \f(CW\*(C`libkrb5\-dev\*(C'\fR package).
.PP
Alternatively, the Authen::SASL::XS or Authen::SASL::Cyrus modules
may be used.  Both rely on Cyrus \f(CW\*(C`libsasl\*(C'\fR.  Authen::SASL::XS is
preferred, but not yet available as an \s-1OS\s0 package.  Authen::SASL::Cyrus
is available on Debian as \f(CW\*(C`libauthen\-sasl\-cyrus\-perl\*(C'\fR and on \s-1RHEL\s0 as
\&\f(CW\*(C`perl\-Authen\-SASL\-Cyrus\*(C'\fR.
.PP
Installing Authen::SASL::XS or Authen::SASL::Cyrus from \s-1CPAN\s0 requires
\&\f(CW\*(C`libsasl\*(C'\fR.  On Debian systems, it is available from \f(CW\*(C`libsasl2\-dev\*(C'\fR; on
\&\s-1RHEL,\s0 it is available in \f(CW\*(C`cyrus\-sasl\-devel\*(C'\fR.
.PP
To use the \s-1GSSAPI\s0 mechanism, first run \f(CW\*(C`kinit\*(C'\fR to authenticate with the ticket
granting service:
.PP
.Vb 1
\&    $ kinit johndoe@EXAMPLE.COM
.Ve
.PP
Configure MongoDB::MongoClient with the principal name as the \f(CW\*(C`username\*(C'\fR
parameter and specify '\s-1GSSAPI\s0' as the \f(CW\*(C`auth_mechanism\*(C'\fR:
.PP
.Vb 5
\&    my $mc = MongoDB::MongoClient\->new(
\&        host => \*(Aqmongodb://mongo.example.com\*(Aq,
\&        username => \*(Aqjohndoe@EXAMPLE.COM\*(Aq,
\&        auth_mechanism => \*(AqGSSAPI\*(Aq,
\&    );
.Ve
.PP
Both can be specified in the \f(CW\*(C`host\*(C'\fR connection string, keeping in mind
that the '@' in the principal name must be encoded as \*(L"%40\*(R":
.PP
.Vb 4
\&    my $mc = MongoDB::MongoClient\->new(
\&        host =>
\&          \*(Aqmongodb://johndoe%40EXAMPLE.COM@mongo.example.com/?authMechanism=GSSAPI\*(Aq,
\&    );
.Ve
.PP
The default service name is 'mongodb'.  It can be changed with the
\&\f(CW\*(C`auth_mechanism_properties\*(C'\fR attribute or in the connection string.
.PP
.Vb 1
\&    auth_mechanism_properties => { SERVICE_NAME => \*(Aqother_service\*(Aq }
\&
\&    mongodb://.../?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other_service
.Ve
.SH "THREAD-SAFETY AND FORK-SAFETY"
.IX Header "THREAD-SAFETY AND FORK-SAFETY"
You \fB\s-1MUST\s0\fR call the \*(L"reconnect\*(R" method on any MongoDB::MongoClient objects
after forking or spawning a thread.
.SH "AUTHORS"
.IX Header "AUTHORS"
.IP "\(bu" 4
David Golden <david@mongodb.com>
.IP "\(bu" 4
Rassi <rassi@mongodb.com>
.IP "\(bu" 4
Mike Friedman <friedo@friedo.com>
.IP "\(bu" 4
Kristina Chodorow <k.chodorow@gmail.com>
.IP "\(bu" 4
Florian Ragwitz <rafl@debian.org>
.SH "COPYRIGHT AND LICENSE"
.IX Header "COPYRIGHT AND LICENSE"
This software is Copyright (c) 2018 by MongoDB, Inc.
.PP
This is free software, licensed under:
.PP
.Vb 1
\&  The Apache License, Version 2.0, January 2004
.Ve

Zerion Mini Shell 1.0