-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathdb.dropDatabase.txt
146 lines (95 loc) · 3.51 KB
/
db.dropDatabase.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
=================
db.dropDatabase()
=================
.. default-domain:: mongodb
.. meta::
:description: Delete a database.
.. facet::
:name: programming_language
:values: shell
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. method:: db.dropDatabase(<writeConcern>)
Removes the current database, deleting the associated data files.
Compatibility
-------------
This method is available in deployments hosted in the following environments:
.. include:: /includes/fact-environments-atlas-only.rst
.. include:: /includes/fact-environments-atlas-support-all.rst
.. include:: /includes/fact-environments-onprem-only.rst
Syntax
------
The :method:`db.dropDatabase()` method takes an optional parameter:
.. list-table::
:header-rows: 1
:widths: 20 80
* - Field
- Description
* - writeConcern
- Optional. A document expressing the :doc:`write concern
</reference/write-concern>` to use if greater than
:writeconcern:`"majority"`.
.. code-block:: javascript
{ w: <value>, j: <boolean>, wtimeout: <number> }
Omit to use the default/minimum write concern of
:writeconcern:`"majority"`.
When issued on a replica set, if the specified write concern
results in fewer member acknowledgments than write concern
:writeconcern:`"majority"`, the operation uses
:writeconcern:`"majority"`. Otherwise, the specified write
concern is used.
.. include:: /includes/extracts/mongos-operations-wc-drop-database.rst
See also :ref:`Behavior <db.dropDatabase-wc>`.
Behavior
--------
The :method:`db.dropDatabase()` wraps the :dbcommand:`dropDatabase`
command.
Locks
~~~~~
The operation takes an exclusive (X)
database lock only.
User Management
~~~~~~~~~~~~~~~
.. include:: /includes/fact-drop-database-users.rst
Indexes
~~~~~~~
.. include:: /includes/extracts/4.4-changes-drop-database-in-progress-indexes.rst
.. include:: /includes/fact-abort-index-build-replica-sets.rst
.. _db.dropDatabase-wc:
Replica Set and Sharded Clusters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Replica Sets
At minimum, :method:`db.dropDatabase()` waits until all collection
drops in the database have propagated to a majority of the replica set
members (i.e. uses the write concern :writeconcern:`"majority"`).
You can specify a write concern to the method. If you specify a write concern
that requires acknowledgment from fewer than the majority, the method uses
write concern :writeconcern:`"majority"`.
If you specify a write concern that requires acknowledgment from
more than the majority, the method uses the specified write concern.
Sharded Clusters
.. include:: /includes/extracts/mongos-operations-wc-drop-database.rst
.. include:: /includes/warning-dropDatabase-shardedCluster.rst
.. include:: /includes/extracts/5.0-changes-dropdatabase-sharding.rst
Change Streams
~~~~~~~~~~~~~~
The :method:`db.dropDatabase()` method and :dbcommand:`dropDatabase`
command create an :ref:`change-event-invalidate` for any
:doc:`/changeStreams` opened on the dropped database or opened on the
collections in the dropped database.
Example
-------
The following example in :binary:`~bin.mongosh` uses the ``use
<database>`` operation to switch the current database to the ``temp``
database and then uses the :method:`db.dropDatabase()` method to drop
the ``temp`` database:
.. code-block:: javascript
use temp
db.dropDatabase()
.. seealso::
:dbcommand:`dropDatabase`