Skip to content

Commit c15fce0

Browse files
authored
PYTHON-3138 copydb was removed in MongoDB 4.2 (#910)
1 parent 75fa14d commit c15fce0

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

doc/examples/copydb.rst

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
Copying a Database
22
==================
33

4-
To copy a database within a single mongod process, or between mongod
5-
servers, simply connect to the target mongod and use the
4+
MongoDB >= 4.2
5+
--------------
6+
7+
Starting in MongoDB version 4.2, the server removes the deprecated ``copydb`` command.
8+
As an alternative, users can use ``mongodump`` and ``mongorestore`` (with the ``mongorestore``
9+
options ``--nsFrom`` and ``--nsTo``).
10+
11+
For example, to copy the ``test`` database from a local instance running on the
12+
default port 27017 to the ``examples`` database on the same instance, you can:
13+
14+
#. Use ``mongodump`` to dump the test database to an archive ``mongodump-test-db``::
15+
16+
mongodump --archive="mongodump-test-db" --db=test
17+
18+
#. Use ``mongorestore`` with ``--nsFrom`` and ``--nsTo`` to restore (with database name change)
19+
from the archive::
20+
21+
mongorestore --archive="mongodump-test-db" --nsFrom='test.*' --nsTo='examples.*'
22+
23+
Include additional options as necessary, such as to specify the uri or host, username,
24+
password and authentication database.
25+
26+
For more info about using ``mongodump`` and ``mongorestore`` see the `Copy a Database`_ example
27+
in the official ``mongodump`` documentation.
28+
29+
MongoDB <= 4.0
30+
--------------
31+
32+
When using MongoDB <= 4.0, it is possible to use the deprecated ``copydb`` command
33+
to copy a database. To copy a database within a single ``mongod`` process, or
34+
between ``mongod`` servers, connect to the target ``mongod`` and use the
635
:meth:`~pymongo.database.Database.command` method::
736

837
>>> from pymongo import MongoClient
@@ -39,3 +68,6 @@ but it has been removed.
3968

4069
.. _copyDatabase function in the mongo shell:
4170
http://docs.mongodb.org/manual/reference/method/db.copyDatabase/
71+
72+
.. _Copy a Database:
73+
https://www.mongodb.com/docs/database-tools/mongodump/#std-label-mongodump-example-copy-clone-database

0 commit comments

Comments
 (0)