/
db.collection.copyTo.txt
67 lines (40 loc) · 1.31 KB
/
db.collection.copyTo.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
======================
db.collection.copyTo()
======================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. method:: db.collection.copyTo(newCollection)
.. deprecated:: 3.0
Copies all documents from ``collection`` into ``newCollection`` using
server-side JavaScript. If ``newCollection`` does not exist, MongoDB
creates it.
.. include:: /includes/extracts/access-eval-copyTo.rst
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Parameter
- Type
- Description
* - ``newCollection``
- string
- The name of the collection to write data to.
.. include:: /includes/warning-copyto-loss-of-type-fidelity.rst
:method:`~db.collection.copyTo()` returns the number of documents
copied. If the copy fails, it throws an exception.
Behavior
--------
Because :method:`~db.collection.copyTo()` uses
:dbcommand:`eval` internally, the copy operations will block all
other operations on the :binary:`~bin.mongod` instance.
Example
-------
The following operation copies all documents from the ``source``
collection into the ``target`` collection.
.. code-block:: javascript
db.source.copyTo(target)