-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
copydb.txt
251 lines (156 loc) · 5.96 KB
/
copydb.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
======
copydb
======
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. dbcommand:: copydb
.. deprecated:: 4.0
MongoDB deprecates :dbcommand:`copydb`
and its helper :method:`db.copyDatabase()`. For information on
alternatives, see :ref:`4.0-deprecate-copydb-clone-cmds`.
Copies a database either from one :binary:`~bin.mongod` instance to the
current :binary:`~bin.mongod` instance or within the current
:binary:`~bin.mongod`. Run :dbcommand:`copydb` in the ``admin`` database
of the destination server with the following syntax:
.. code-block:: javascript
{ copydb: 1,
fromhost: <hostname>,
fromdb: <database>,
todb: <database>,
slaveOk: <bool>,
writeConcern: <document>,
bypassDocumentValidation: <boolean> }
:dbcommand:`copydb` accepts the following options:
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Field
- Type
- Description
* - ``fromhost``
- string
- Optional. The hostname of the source :binary:`~bin.mongod` instance. Omit
to copy databases within the same :binary:`~bin.mongod` instance.
* - ``fromdb``
- string
- Name of the source database.
* - ``todb``
- string
- Name of the target database.
* - ``slaveOk``
- boolean
- Optional. Set ``slaveOK`` to ``true`` to allow :dbcommand:`copydb` to copy data from
secondary members as well as the primary. ``fromhost`` must also be
set.
* - ``writeConcern``
- document
- Optional. A document that expresses the :doc:`write concern </reference/write-concern>`
for the operation. Omit to use the default write
concern.
* - ``bypassDocumentValidation``
- boolean
- Optional. Enables :dbcommand:`copydb` to bypass document validation
during the operation. This lets you insert documents that do not
meet the validation requirements.
.. versionadded:: 3.2
The :binary:`~bin.mongo` shell provides the :method:`db.copyDatabase()`
wrapper for the :dbcommand:`copydb` command.
Behavior
--------
Feature Compatibility Version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. include:: /includes/3.6-featureCompatibility-copy-data.rst
Destination
~~~~~~~~~~~
.. include:: /includes/extracts/fact-copydb-cmd-behavior-destination.rst
.. _copydb-access-control:
Authentication to Source ``mongod`` Instance
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To copy from another :binary:`~bin.mongod` instance (``fromhost``) that
enforces :setting:`access control <security.authorization>`, then you
must use the :binary:`~bin.mongo` shell method
:method:`db.copyDatabase()`.
Concurrency
~~~~~~~~~~~
.. include:: /includes/extracts/fact-copydb-cmd-behavior-concurrency.rst
Indexes
~~~~~~~
.. include:: /includes/fact-copydb-cmd-behavior-indexes.rst
.. |command| replace:: ``copydb``
Replica Sets
~~~~~~~~~~~~
With :term:`read preference` configured to set the ``slaveOk`` option
to ``true``, you may run :dbcommand:`copydb` on a :term:`secondary`
member of a :term:`replica set`.
Sharded Clusters
~~~~~~~~~~~~~~~~
- Do not use :dbcommand:`copydb` from a :binary:`~bin.mongos` instance.
- Do not use :dbcommand:`copydb` to copy databases that contain sharded
collections.
.. _copydb-required-access:
Required Access
---------------
.. _copydb-fromdb-access:
Source Database (``fromdb``)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you are copying within the same :program:`mongod` instance that
enforces access control, you must have the appropriate authorization.
If you are copying from a different :program:`mongod` instance that
enforces access control, see :method:`db.copyDatabase()`.
Source is non-``admin`` Database
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. include:: /includes/extracts/access-copydb-source-not-admin.rst
Source is ``admin`` Database
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. include:: /includes/extracts/access-copydb-source-admin.rst
Target Database (``todb``)
~~~~~~~~~~~~~~~~~~~~~~~~~~
If the :binary:`~bin.mongod` instance of the *target* database (``todb``)
enforces :setting:`access control <security.authorization>`, you must
have proper authorization for the *target* database.
Copy from non-``admin`` Database
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. include:: /includes/extracts/access-copydb-target-non-admin-source.rst
Copy from ``admin`` Database
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. include:: /includes/extracts/access-copydb-target-admin-source.rst
Examples
--------
Copy from the Same ``mongod`` Instance
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To copy from the same host, omit the ``fromhost`` field.
The following command copies the ``test`` database to a new ``records``
database on the current :binary:`~bin.mongod` instance:
.. code-block:: javascript
db.adminCommand({
copydb: 1,
fromdb: "test",
todb: "records"
})
Copy from a Remote Host to the Current Host
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To copy from a remote host, include the ``fromhost`` field.
The following command copies the ``test`` database from the remote host
``example.net`` to a new ``records`` database on the current
:binary:`~bin.mongod` instance:
.. code-block:: javascript
db.adminCommand({
copydb: 1,
fromdb: "test",
todb: "records",
fromhost: "example.net"
})
To copy from another :binary:`~bin.mongod` instance (``fromhost``) that
enforces :setting:`access control <security.authorization>`, then you
must use the :binary:`~bin.mongo` shell method
:method:`db.copyDatabase()`.
.. seealso::
- :method:`db.copyDatabase()`
- :dbcommand:`clone` and :method:`db.cloneDatabase()`
- :doc:`/core/backups`