MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / Database

Class Database

pymongo/synchronous/database.py:61–1479  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59
60
61class Database(common.BaseObject, Generic[_DocumentType]):
62 def __init__(
63 self,
64 client: MongoClient[_DocumentType],
65 name: str,
66 codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None,
67 read_preference: Optional[_ServerMode] = None,
68 write_concern: Optional[WriteConcern] = None,
69 read_concern: Optional[ReadConcern] = None,
70 ) -> None:
71 """Get a database by client and name.
72
73 Raises :class:`TypeError` if `name` is not an instance of
74 :class:`str`. Raises :class:`~pymongo.errors.InvalidName` if
75 `name` is not a valid database name.
76
77 :param client: A :class:`~pymongo.mongo_client.MongoClient` instance.
78 :param name: The database name.
79 :param codec_options: An instance of
80 :class:`~bson.codec_options.CodecOptions`. If ``None`` (the
81 default) client.codec_options is used.
82 :param read_preference: The read preference to use. If
83 ``None`` (the default) client.read_preference is used.
84 :param write_concern: An instance of
85 :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the
86 default) client.write_concern is used.
87 :param read_concern: An instance of
88 :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the
89 default) client.read_concern is used.
90
91 .. seealso:: The MongoDB documentation on `databases <https://dochub.mongodb.org/core/databases>`_.
92
93 .. versionchanged:: 4.0
94 Removed the eval, system_js, error, last_status, previous_error,
95 reset_error_history, authenticate, logout, collection_names,
96 current_op, add_user, remove_user, profiling_level,
97 set_profiling_level, and profiling_info methods.
98 See the :ref:`pymongo4-migration-guide`.
99
100 .. versionchanged:: 3.2
101 Added the read_concern option.
102
103 .. versionchanged:: 3.0
104 Added the codec_options, read_preference, and write_concern options.
105 :class:`~pymongo.database.Database` no longer returns an instance
106 of :class:`~pymongo.collection.Collection` for attribute names
107 with leading underscores. You must use dict-style lookups instead::
108
109 db['__my_collection__']
110
111 Not:
112
113 db.__my_collection__
114 """
115 super().__init__(
116 codec_options or client.codec_options,
117 read_preference or client.read_preference,
118 write_concern or client.write_concern,

Callers 15

test_generic_argumentsFunction · 0.90
test_get_dbMethod · 0.90
test_nameMethod · 0.90
test_equalityMethod · 0.90
test_hashableMethod · 0.90
test_get_collMethod · 0.90
test_reprMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_generic_argumentsFunction · 0.72
test_get_dbMethod · 0.72
test_nameMethod · 0.72
test_equalityMethod · 0.72
test_hashableMethod · 0.72
test_get_collMethod · 0.72
test_reprMethod · 0.72