mongo_replica_set_client
– Tools for connecting to a MongoDB replica set
Deprecated. See High Availability and PyMongo.
class pymongo.mongo_replica_set_client.MongoReplicaSetClient(hosts_or_uri, document_class=dict, tz_aware=False, connect=True, \*kwargs*)
Client for a MongoDB instance, a replica set, or a set of mongoses.
The client object is thread-safe and has connection-pooling built in. If an operation fails because of a network error, ConnectionFailure is raised and the client reconnects in the background. Application code should handle this exception (recognizing that the operation failed) and then continue to execute.
The host parameter can be a full mongodb URI, in addition to a simple hostname. It can also be a list of hostnames or URIs. Any port specified in the host string(s) will override the port parameter. If multiple mongodb URIs containing database or auth information are passed, the last database, username, and password present will be used. For username and passwords reserved characters like ‘:’, ‘/’, ‘+’ and ‘@’ must be percent encoded following RFC 2396:
try:
# Python 3.x
from urllib.parse import quote_plus
except ImportError:
# Python 2.x
from urllib import quote_plus
uri = "mongodb://%s:%s@%s" % (
quote_plus(user), quote_plus(password), host)
client = MongoClient(uri)
Unix domain sockets are also supported. The socket path must be percent encoded in the URI:
uri = "mongodb://%s:%s@%s" % (
quote_plus(user), quote_plus(password), quote_plus(socket_path))
client = MongoClient(uri)
But not when passed as a simple hostname:
client = MongoClient('/tmp/mongodb-27017.sock')
Starting with version 3.6, PyMongo supports mongodb+srv:// URIs. The URI must include one, and only one, hostname. The hostname will be resolved to one or more DNS SRV records which will be used as the seed list for connecting to the MongoDB deployment. When using SRV URIs, the authSource and replicaSet configuration options can be specified using TXT records. See the Initial DNS Seedlist Discovery spec for more details. Note that the use of SRV URIs implicitly enables TLS support. Pass tls=false in the URI to override.
Note
MongoClient creation will block waiting for answers from DNS when mongodb+srv:// URIs are used.
Note
Starting with version 3.0 the MongoClient
constructor no longer blocks while connecting to the server or servers, and it no longer raises ConnectionFailure if they are unavailable, nor ConfigurationError if the user’s credentials are wrong. Instead, the constructor returns immediately and launches the connection process on background threads. You can check if the server is available like this:
from pymongo.errors import ConnectionFailure
client = MongoClient()
try:
# The ping command is cheap and does not require auth.
client.admin.command('ping')
except ConnectionFailure:
print("Server not available")
Warning
When using PyMongo in a multiprocessing context, please read Using PyMongo with Multiprocessing first.
Note
Many of the following options can be passed using a MongoDB URI or keyword parameters. If the same option is passed in a URI and as a keyword parameter the keyword parameter takes precedence.
Parameters
host (optional): hostname or IP address or Unix domain socket path of a single mongod or mongos instance to connect to, or a mongodb URI, or a list of hostnames / mongodb URIs. If host is an IPv6 literal it must be enclosed in ‘[‘ and ‘]’ characters following the RFC2732 URL syntax (e.g. ‘[::1]’ for localhost). Multihomed and round robin DNS addresses are not supported.
port (optional): port number on which to connect
document_class (optional): default class to use for documents returned from queries on this client
tz_aware (optional): if
True
, datetime instances returned as values in a document by thisMongoClient
will be timezone aware (otherwise they will be naive)connect (optional): if
True
(the default), immediately begin connecting to MongoDB in the background. Otherwise connect on the first operation.type_registry (optional): instance of TypeRegistry to enable encoding and decoding of custom types.
Other optional parameters can be passed as keyword arguments:
directConnection (optional): if
True
, forces this client toconnect directly to the specified MongoDB host as a standalone. If
false
, the client connects to the entire replica set of which the given MongoDB host(s) is a part. If this isTrue
and a mongodb+srv:// URI or a URI containing multiple seeds is provided, an exception will be raised.maxPoolSize (optional): The maximum allowable number of concurrent connections to each connected server. Requests to a server will block if there are maxPoolSize outstanding connections to the requested server. Defaults to 100. Cannot be 0.
minPoolSize (optional): The minimum required number of concurrent connections that the pool will maintain to each connected server. Default is 0.
maxIdleTimeMS (optional): The maximum number of milliseconds that a connection can remain idle in the pool before being removed and replaced. Defaults to None (no limit).
socketTimeoutMS: (integer or None) Controls how long (in milliseconds) the driver will wait for a response after sending an ordinary (non-monitoring) database operation before concluding that a network error has occurred.
0
orNone
means no timeout. Defaults toNone
(no timeout).connectTimeoutMS: (integer or None) Controls how long (in milliseconds) the driver will wait during server monitoring when connecting a new socket to a server before concluding the server is unavailable.
0
orNone
means no timeout. Defaults to20000
(20 seconds).server_selector: (callable or None) Optional, user-provided function that augments server selection rules. The function should accept as an argument a list of ServerDescription objects and return a list of server descriptions that should be considered suitable for the desired operation.
serverSelectionTimeoutMS: (integer) Controls how long (in milliseconds) the driver will wait to find an available, appropriate server to carry out a database operation; while it is waiting, multiple server monitoring operations may be carried out, each controlled by connectTimeoutMS. Defaults to
30000
(30 seconds).waitQueueTimeoutMS: (integer or None) How long (in milliseconds) a thread will wait for a socket from the pool if the pool has no free sockets. Defaults to
None
(no timeout).waitQueueMultiple: (integer or None) Multiplied by maxPoolSize to give the number of threads allowed to wait for a socket at one time. Defaults to
None
(no limit).heartbeatFrequencyMS: (optional) The number of milliseconds between periodic server checks, or None to accept the default frequency of 10 seconds.
appname: (string or None) The name of the application that created this MongoClient instance. MongoDB 3.4 and newer will print this value in the server log upon establishing each connection. It is also recorded in the slow query log and profile collections.
driver: (pair or None) A driver implemented on top of PyMongo can pass a DriverInfo to add its name, version, and platform to the message printed in the server log when establishing a connection.
event_listeners: a list or tuple of event listeners. See monitoring for details.
retryWrites: (boolean) Whether supported write operations executed within this MongoClient will be retried once after a network error on MongoDB 3.6+. Defaults to
True
. The supported write operations are:bulk_write(), as long as UpdateMany or DeleteMany are not included.
Unsupported write operations include, but are not limited to, aggregate() using the
$out
pipeline operator and any operation with an unacknowledged write concern (e.g. {w: 0})). See https://github.com/mongodb/specifications/blob/master/source/retryable-writes/retryable-writes.rstretryReads: (boolean) Whether supported read operations executed within this MongoClient will be retried once after a network error on MongoDB 3.6+. Defaults to
True
. The supported read operations are: find(), find_one(), aggregate() without$out
, distinct(), count(), estimated_document_count(), count_documents(), pymongo.collection.Collection.watch(), list_indexes(), pymongo.database.Database.watch(), list_collections(), pymongo.mongo_client.MongoClient.watch(), and list_databases().Unsupported read operations include, but are not limited to: map_reduce(), inline_map_reduce(), command(), and any getMore operation on a cursor.
Enabling retryable reads makes applications more resilient to transient errors such as network failures, database upgrades, and replica set failovers. For an exact definition of which errors trigger a retry, see the retryable reads specification.
socketKeepAlive: (boolean) DEPRECATED Whether to send periodic keep-alive packets on connected sockets. Defaults to
True
. Disabling it is not recommended, see https://docs.mongodb.com/manual/faq/diagnostics/#does-tcp-keepalive-time-affect-mongodb-deployments”,compressors: Comma separated list of compressors for wire protocol compression. The list is used to negotiate a compressor with the server. Currently supported options are “snappy”, “zlib” and “zstd”. Support for snappy requires the python-snappy package. zlib support requires the Python standard library zlib module. zstd requires the zstandard package. By default no compression is used. Compression support must also be enabled on the server. MongoDB 3.4+ supports snappy compression. MongoDB 3.6 adds support for zlib. MongoDB 4.2 adds support for zstd.
zlibCompressionLevel: (int) The zlib compression level to use when zlib is used as the wire protocol compressor. Supported values are -1 through 9. -1 tells the zlib library to use its default compression level (usually 6). 0 means no compression. 1 is best speed. 9 is best compression. Defaults to -1.
uuidRepresentation: The BSON representation to use when encoding from and decoding to instances of UUID. Valid values are pythonLegacy (the default), javaLegacy, csharpLegacy, standard and unspecified. New applications should consider setting this to standard for cross language compatibility. See Handling UUID Data for details.
unicode_decode_error_handler: The error handler to apply when a Unicode-related error occurs during BSON decoding that would otherwise raise UnicodeDecodeError. Valid options include ‘strict’, ‘replace’, and ‘ignore’. Defaults to ‘strict’.
Write Concern options:
(Only set if passed. No default values.)
w: (integer or string) If this is a replica set, write operations will block until they have been replicated to the specified number or tagged set of servers. w=<int> always includes the replica set primary (e.g. w=3 means write to the primary and wait until replicated to two secondaries). Passing w=0 disables write acknowledgement and all other write concern options.
wTimeoutMS: (integer) Used in conjunction with w. Specify a value in milliseconds to control how long to wait for write propagation to complete. If replication does not complete in the given timeframe, a timeout exception is raised. Passing wTimeoutMS=0 will cause write operations to wait indefinitely.
journal: If
True
block until write operations have been committed to the journal. Cannot be used in combination with fsync. 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 with an exception if this option is used when the server is running without journaling.fsync: If
True
and the server is running without journaling, blocks until the server has synced all data files to disk. If the server is running with journaling, this acts the same as the j option, blocking until write operations have been committed to the journal. Cannot be used in combination with j.
Replica set keyword arguments for connecting with a replica set - either directly or via a mongos:
- replicaSet: (string or None) The name of the replica set to connect to. The driver will verify that all servers it connects to match this name. Implies that the hosts specified are a seed list and the driver should attempt to find all members of the set. Defaults to
None
.
Read Preference:
readPreference: The replica set read preference for this client. One of
primary
,primaryPreferred
,secondary
,secondaryPreferred
, ornearest
. Defaults toprimary
.readPreferenceTags: Specifies a tag set as a comma-separated list of colon-separated key-value pairs. For example
dc:ny,rack:1
. Defaults toNone
.maxStalenessSeconds: (integer) The maximum estimated length of time a replica set secondary can fall behind the primary in replication before it will no longer be selected for operations. Defaults to
-1
, meaning no maximum. If maxStalenessSeconds is set, it must be a positive integer greater than or equal to 90 seconds.
See also
Authentication:
username: A string.
password: A string.
Although username and password must be percent-escaped in a MongoDB URI, they must not be percent-escaped when passed as parameters. In this example, both the space and slash special characters are passed as-is:
MongoClient(username="user name", password="pass/word")
authSource: The database to authenticate on. Defaults to the database specified in the URI, if provided, or to “admin”.
authMechanism: See MECHANISMS for options. If no mechanism is specified, PyMongo automatically uses MONGODB-CR when connected to a pre-3.0 version of MongoDB, SCRAM-SHA-1 when connected to MongoDB 3.0 through 3.6, and negotiates the mechanism to use (SCRAM-SHA-1 or SCRAM-SHA-256) when connected to MongoDB 4.0+.
authMechanismProperties: Used to specify authentication mechanism specific options. To specify the service name for GSSAPI authentication pass authMechanismProperties=’SERVICE_NAME:<service name>’. To specify the session token for MONGODB-AWS authentication pass
authMechanismProperties='AWS_SESSION_TOKEN:<session token>'
.
See also
TLS/SSL configuration:
tls: (boolean) If
True
, create the connection to the server using transport layer security. Defaults toFalse
.tlsInsecure: (boolean) Specify whether TLS constraints should be relaxed as much as possible. Setting
tlsInsecure=True
impliestlsAllowInvalidCertificates=True
andtlsAllowInvalidHostnames=True
. Defaults toFalse
. Think very carefully before setting this toTrue
as it dramatically reduces the security of TLS.tlsAllowInvalidCertificates: (boolean) If
True
, continues the TLS handshake regardless of the outcome of the certificate verification process. If this isFalse
, and a value is not provided fortlsCAFile
, PyMongo will attempt to load system provided CA certificates. If the python version in use does not support loading system CA certificates then thetlsCAFile
parameter must point to a file of CA certificates.tlsAllowInvalidCertificates=False
impliestls=True
. Defaults toFalse
. Think very carefully before setting this toTrue
as that could make your application vulnerable to on-path attackers.tlsAllowInvalidHostnames: (boolean) If
True
, disables TLS hostname verification.tlsAllowInvalidHostnames=False
impliestls=True
. Defaults toFalse
. Think very carefully before setting this toTrue
as that could make your application vulnerable to on-path attackers.tlsCAFile: A file containing a single or a bundle of “certification authority” certificates, which are used to validate certificates passed from the other end of the connection. Implies
tls=True
. Defaults toNone
.tlsCertificateKeyFile: A file containing the client certificate and private key. Implies
tls=True
. Defaults toNone
.tlsCRLFile: A file containing a PEM or DER formatted certificate revocation list. Only supported by python 2.7.9+ (pypy 2.5.1+). Implies
tls=True
. Defaults toNone
.tlsCertificateKeyFilePassword: The password or passphrase for decrypting the private key in
tlsCertificateKeyFile
. Only necessary if the private key is encrypted. Only supported by python 2.7.9+ (pypy 2.5.1+) and 3.3+. Defaults toNone
.tlsDisableOCSPEndpointCheck: (boolean) If
True
, disables certificate revocation status checking via the OCSP responder specified on the server certificate. Defaults toFalse
.ssl: (boolean) Alias for
tls
.
Read Concern options:
(If not set explicitly, this will use the server default)
- readConcernLevel: (string) The read concern level specifies the level of isolation for read operations. For example, a read operation using a read concern level of
majority
will only return data that has been written to a majority of nodes. If the level is left unspecified, the server default will be used.
Client side encryption options:
(If not set explicitly, client side encryption will not be enabled.)
auto_encryption_opts: A AutoEncryptionOpts which configures this client to automatically encrypt collection commands and automatically decrypt results. See Automatic Client-Side Field Level Encryption for an example. If a
MongoClient
is configured withauto_encryption_opts
and a non-NonemaxPoolSize
, a separate internalMongoClient
is created if any of the following are true:A
key_vault_client
is not passed to AutoEncryptionOptsbypass_auto_encrpytion=False
is passed to AutoEncryptionOpts
Versioned API options:
(If not set explicitly, Versioned API will not be enabled.)
- server_api: A ServerApi which configures this client to use Versioned API. See MongoDB Versioned API for details.
See also
The MongoDB documentation on connections.
Changed in version 3.12: Added the server_api
keyword argument. The following keyword arguments were deprecated:
ssl_certfile
andssl_keyfile
were deprecated in favor oftlsCertificateKeyFile
.
Changed in version 3.11: Added the following keyword arguments and URI options:
tlsDisableOCSPEndpointCheck
directConnection
Changed in version 3.9: Added the retryReads
keyword argument and URI option. Added the tlsInsecure
keyword argument and URI option. The following keyword arguments and URI options were deprecated:
wTimeout
was deprecated in favor ofwTimeoutMS
.
j
was deprecated in favor ofjournal
.
ssl_cert_reqs
was deprecated in favor oftlsAllowInvalidCertificates
.
ssl_match_hostname
was deprecated in favor oftlsAllowInvalidHostnames
.
ssl_ca_certs
was deprecated in favor oftlsCAFile
.
ssl_certfile
was deprecated in favor oftlsCertificateKeyFile
.
ssl_crlfile
was deprecated in favor oftlsCRLFile
.
ssl_pem_passphrase
was deprecated in favor oftlsCertificateKeyFilePassword
.
Changed in version 3.9: retryWrites
now defaults to True
.
Changed in version 3.8: Added the server_selector
keyword argument. Added the type_registry
keyword argument.
Changed in version 3.7: Added the driver
keyword argument.
Changed in version 3.6: Added support for mongodb+srv:// URIs. Added the retryWrites
keyword argument and URI option.
Changed in version 3.5: Add username
and password
options. Document the authSource
, authMechanism
, and authMechanismProperties
options. Deprecated the socketKeepAlive
keyword argument and URI option. socketKeepAlive
now defaults to True
.
Changed in version 3.0: MongoClient is now the one and only client class for a standalone server, mongos, or replica set. It includes the functionality that had been split into MongoReplicaSetClient
: it can connect to a replica set, discover all its members, and monitor the set for stepdowns, elections, and reconfigs.
The MongoClient constructor no longer blocks while connecting to the server or servers, and it no longer raises ConnectionFailure if they are unavailable, nor ConfigurationError if the user’s credentials are wrong. Instead, the constructor returns immediately and launches the connection process on background threads.
Therefore the alive
method is removed since it no longer provides meaningful information; even if the client is disconnected, it may discover a server in time to fulfill the next operation.
In PyMongo 2.x, MongoClient accepted a list of standalone MongoDB servers and used the first it could connect to:
MongoClient(['host1.com:27017', 'host2.com:27017'])
A list of multiple standalones is no longer supported; if multiple servers are listed they must be members of the same replica set, or mongoses in the same sharded cluster.
The behavior for a list of mongoses is changed from “high availability” to “load balancing”. Before, the client connected to the lowest-latency mongos in the list, and used it until a network error prompted it to re-evaluate all mongoses’ latencies and reconnect to one of them. In PyMongo 3, the client monitors its network latency to all the mongoses continuously, and distributes operations evenly among those with the lowest latency. See mongos Load Balancing for more information.
The connect
option is added.
The start_request
, in_request
, and end_request
methods are removed, as well as the auto_start_request
option.
The copy_database
method is removed, see the copy_database examples for alternatives.
The MongoClient.disconnect()
method is removed; it was a synonym for close()
.
MongoClient no longer returns an instance of Database for attribute names with leading underscores. You must use dict-style lookups instead:
client['__my_database__']
Not:
client.__my_database__
close()
Cleanup client resources and disconnect from MongoDB.
On MongoDB >= 3.6, end all server sessions created by this client by sending one or more endSessions commands.
Close all sockets in the connection pools and stop the monitor threads. If this instance is used again it will be automatically re-opened and the threads restarted unless auto encryption is enabled. A client enabled with auto encryption cannot be used again after being closed; any attempt will raise InvalidOperation.
Changed in version 3.6: End all server sessions created by this client.
c[db_name] || c.db_name
Get the db_name Database on MongoReplicaSetClient c.
Raises InvalidName if an invalid database name is used.
primary
The (host, port) of the current primary of the replica set.
Returns
None
if this client is not connected to a replica set, there is no primary, or this client was created without the replicaSet option.New in version 3.0: MongoClient gained this property in version 3.0 when MongoReplicaSetClient’s functionality was merged in.
secondaries
The secondary members known to this client.
A sequence of (host, port) pairs. Empty if this client is not connected to a replica set, there are no visible secondaries, or this client was created without the replicaSet option.
New in version 3.0: MongoClient gained this property in version 3.0 when MongoReplicaSetClient’s functionality was merged in.
arbiters
Arbiters in the replica set.
A sequence of (host, port) pairs. Empty if this client is not connected to a replica set, there are no arbiters, or this client was created without the replicaSet option.
max_pool_size
The maximum allowable number of concurrent connections to each connected server. Requests to a server will block if there are maxPoolSize outstanding connections to the requested server. Defaults to 100. Cannot be 0.
When a server’s pool has reached max_pool_size, operations for that server block waiting for a socket to be returned to the pool. If
waitQueueTimeoutMS
is set, a blocked operation will raise ConnectionFailure after a timeout. By defaultwaitQueueTimeoutMS
is not set.max_bson_size
The largest BSON object the connected server accepts in bytes.
If the client is not connected, this will block until a connection is established or raise ServerSelectionTimeoutError if no server is available.
max_message_size
The largest message the connected server accepts in bytes.
If the client is not connected, this will block until a connection is established or raise ServerSelectionTimeoutError if no server is available.
local_threshold_ms
The local threshold for this instance.
codec_options
Read only access to the CodecOptions of this instance.
read_preference
Read only access to the read preference of this instance.
Changed in version 3.0: The read_preference attribute is now read only.
write_concern
Read only access to the WriteConcern of this instance.
Changed in version 3.0: The write_concern attribute is now read only.
database_names(session=None)
DEPRECATED: Get a list of the names of all databases on the connected server.
Parameters
- session (optional): a ClientSession.
Changed in version 3.7: Deprecated. Use
list_database_names()
instead.Changed in version 3.6: Added
session
parameter.drop_database(name_or_database, session=None)
Drop a database.
Raises TypeError if name_or_database is not an instance of
basestring
(str in python 3) or Database.Parameters
name_or_database: the name of a database to drop, or a Database instance representing the database to drop
session (optional): a ClientSession.
Changed in version 3.6: Added
session
parameter.Note
The write_concern of this client is automatically applied to this operation when using MongoDB >= 3.4.
Changed in version 3.4: Apply this client’s write concern automatically to this operation when connected to MongoDB >= 3.4.
get_database(name=None, codec_options=None, read_preference=None, write_concern=None, read_concern=None)
Get a Database with the given name and options.
Useful for creating a Database with different codec options, read preference, and/or write concern from this
MongoClient
.>>> client.read_preference
Primary()
>>> db1 = client.test
>>> db1.read_preference
Primary()
>>> from pymongo import ReadPreference
>>> db2 = client.get_database(
... 'test', read_preference=ReadPreference.SECONDARY)
>>> db2.read_preference
Secondary(tag_sets=None)
Parameters
name (optional): The name of the database - a string. If
None
(the default) the database named in the MongoDB connection URI is returned.codec_options (optional): An instance of CodecOptions. If
None
(the default) the codec_options of thisMongoClient
is used.read_preference (optional): The read preference to use. If
None
(the default) the read_preference of thisMongoClient
is used. See read_preferences for options.write_concern (optional): An instance of WriteConcern. If
None
(the default) the write_concern of thisMongoClient
is used.read_concern (optional): An instance of ReadConcern. If
None
(the default) theread_concern
of thisMongoClient
is used.
Changed in version 3.5: The name parameter is now optional, defaulting to the database named in the MongoDB connection URI.
close_cursor(cursor_id, address=None)
DEPRECATED - Send a kill cursors message soon with the given id.
Raises TypeError if cursor_id is not an instance of
(int, long)
. What closing the cursor actually means depends on this client’s cursor manager.This method may be called from a Cursor destructor during garbage collection, so it isn’t safe to take a lock or do network I/O. Instead, we schedule the cursor to be closed soon on a background thread.
Parameters
cursor_id: id of cursor to close
address (optional): (host, port) pair of the cursor’s server. If it is not provided, the client attempts to close the cursor on the primary or standalone, or a mongos server.
Changed in version 3.7: Deprecated.
Changed in version 3.0: Added
address
parameter.kill_cursors(cursor_ids, address=None)
DEPRECATED - Send a kill cursors message soon with the given ids.
Raises TypeError if cursor_ids is not an instance of
list
.Parameters
cursor_ids: list of cursor ids to kill
address (optional): (host, port) pair of the cursor’s server. If it is not provided, the client attempts to close the cursor on the primary or standalone, or a mongos server.
Changed in version 3.3: Deprecated.
Changed in version 3.0: Now accepts an address argument. Schedules the cursors to be closed on a background thread instead of sending the message immediately.
set_cursor_manager(manager_class)
DEPRECATED - Set this client’s cursor manager.
Raises TypeError if manager_class is not a subclass of CursorManager. A cursor manager handles closing cursors. Different managers can implement different policies in terms of when to actually kill a cursor that has been closed.
Parameters
- manager_class: cursor manager to use
Changed in version 3.3: Deprecated, for real this time.
Changed in version 3.0: Undeprecated.
get_default_database(default=None, codec_options=None, read_preference=None, write_concern=None, read_concern=None)
Get the database named in the MongoDB connection URI.
>>> uri = 'mongodb://host/my_database'
>>> client = MongoClient(uri)
>>> db = client.get_default_database()
>>> assert db.name == 'my_database'
>>> db = client.get_database()
>>> assert db.name == 'my_database'
Useful in scripts where you want to choose which database to use based only on the URI in a configuration file.
Parameters
default (optional): the database name to use if no database name was provided in the URI.
codec_options (optional): An instance of CodecOptions. If
None
(the default) the codec_options of thisMongoClient
is used.read_preference (optional): The read preference to use. If
None
(the default) the read_preference of thisMongoClient
is used. See read_preferences for options.write_concern (optional): An instance of WriteConcern. If
None
(the default) the write_concern of thisMongoClient
is used.read_concern (optional): An instance of ReadConcern. If
None
(the default) theread_concern
of thisMongoClient
is used.
Changed in version 3.8: Undeprecated. Added the
default
,codec_options
,read_preference
,write_concern
andread_concern
parameters.Changed in version 3.5: Deprecated, use get_database() instead.