@@ -1752,8 +1752,9 @@ def drop_database(self, name_or_database, session=None):
17521752 parse_write_concern_error = True ,
17531753 session = session )
17541754
1755- def get_default_database (self ):
1756- """DEPRECATED - Get the database named in the MongoDB connection URI.
1755+ def get_default_database (self , default = None , codec_options = None ,
1756+ read_preference = None , write_concern = None , read_concern = None ):
1757+ """Get the database named in the MongoDB connection URI.
17571758
17581759 >>> uri = 'mongodb://host/my_database'
17591760 >>> client = MongoClient(uri)
@@ -1765,15 +1766,41 @@ def get_default_database(self):
17651766 Useful in scripts where you want to choose which database to use
17661767 based only on the URI in a configuration file.
17671768
1769+ :Parameters:
1770+ - `default` (optional): the database name to use if no database name
1771+ was provided in the URI.
1772+ - `codec_options` (optional): An instance of
1773+ :class:`~bson.codec_options.CodecOptions`. If ``None`` (the
1774+ default) the :attr:`codec_options` of this :class:`MongoClient` is
1775+ used.
1776+ - `read_preference` (optional): The read preference to use. If
1777+ ``None`` (the default) the :attr:`read_preference` of this
1778+ :class:`MongoClient` is used. See :mod:`~pymongo.read_preferences`
1779+ for options.
1780+ - `write_concern` (optional): An instance of
1781+ :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the
1782+ default) the :attr:`write_concern` of this :class:`MongoClient` is
1783+ used.
1784+ - `read_concern` (optional): An instance of
1785+ :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the
1786+ default) the :attr:`read_concern` of this :class:`MongoClient` is
1787+ used.
1788+
1789+ .. versionchanged:: 3.8
1790+ Undeprecated. Added the ``default``, ``codec_options``,
1791+ ``read_preference``, ``write_concern`` and ``read_concern``
1792+ parameters.
1793+
17681794 .. versionchanged:: 3.5
17691795 Deprecated, use :meth:`get_database` instead.
17701796 """
1771- warnings .warn ("get_default_database is deprecated. Use get_database "
1772- "instead." , DeprecationWarning , stacklevel = 2 )
1773- if self .__default_database_name is None :
1774- raise ConfigurationError ('No default database defined' )
1797+ if self .__default_database_name is None and default is None :
1798+ raise ConfigurationError (
1799+ 'No default database name defined or provided.' )
17751800
1776- return self [self .__default_database_name ]
1801+ return database .Database (
1802+ self , self .__default_database_name or default , codec_options ,
1803+ read_preference , write_concern , read_concern )
17771804
17781805 def get_database (self , name = None , codec_options = None , read_preference = None ,
17791806 write_concern = None , read_concern = None ):
0 commit comments