Drop a database. Raises :class:`TypeError` if `name_or_database` is not an instance of :class:`str` or :class:`~pymongo.database.Database`. :param name_or_database: the name of a database to drop, or a :class:`~pymongo.database.Database` instance representing th
(
self,
name_or_database: Union[str, database.Database[_DocumentTypeArg]],
session: Optional[client_session.ClientSession] = None,
comment: Optional[Any] = None,
)
| 2432 | |
| 2433 | @_csot.apply |
| 2434 | def drop_database( |
| 2435 | self, |
| 2436 | name_or_database: Union[str, database.Database[_DocumentTypeArg]], |
| 2437 | session: Optional[client_session.ClientSession] = None, |
| 2438 | comment: Optional[Any] = None, |
| 2439 | ) -> None: |
| 2440 | """Drop a database. |
| 2441 | |
| 2442 | Raises :class:`TypeError` if `name_or_database` is not an instance of |
| 2443 | :class:`str` or :class:`~pymongo.database.Database`. |
| 2444 | |
| 2445 | :param name_or_database: the name of a database to drop, or a |
| 2446 | :class:`~pymongo.database.Database` instance representing the |
| 2447 | database to drop |
| 2448 | :param session: a |
| 2449 | :class:`~pymongo.client_session.ClientSession`. |
| 2450 | :param comment: A user-provided comment to attach to this |
| 2451 | command. |
| 2452 | |
| 2453 | .. versionchanged:: 4.1 |
| 2454 | Added ``comment`` parameter. |
| 2455 | |
| 2456 | .. versionchanged:: 3.6 |
| 2457 | Added ``session`` parameter. |
| 2458 | |
| 2459 | .. note:: The :attr:`~pymongo.mongo_client.MongoClient.write_concern` of |
| 2460 | this client is automatically applied to this operation. |
| 2461 | |
| 2462 | .. versionchanged:: 3.4 |
| 2463 | Apply this client's write concern automatically to this operation |
| 2464 | when connected to MongoDB >= 3.4. |
| 2465 | |
| 2466 | """ |
| 2467 | name = name_or_database |
| 2468 | if isinstance(name, database.Database): |
| 2469 | name = name.name |
| 2470 | |
| 2471 | if not isinstance(name, str): |
| 2472 | raise TypeError( |
| 2473 | f"name_or_database must be an instance of str or a Database, not {type(name)}" |
| 2474 | ) |
| 2475 | |
| 2476 | self[name].command( |
| 2477 | {"dropDatabase": 1, "comment": comment}, |
| 2478 | read_preference=ReadPreference.PRIMARY, |
| 2479 | write_concern=self._write_concern_for(session), |
| 2480 | parse_write_concern_error=True, |
| 2481 | session=session, |
| 2482 | ) |
| 2483 | |
| 2484 | @_csot.apply |
| 2485 | def bulk_write( |