Skip to content

Commit 1f25f15

Browse files
committed
Update renameCollection documentation
1 parent 83b8d5b commit 1f25f15

7 files changed

+158
-29
lines changed

docs/includes/apiargs-MongoDBCollection-method-renameCollection-option.yaml renamed to docs/includes/apiargs-MongoDBCollection-method-rename-option.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ post: |
77
source:
88
file: apiargs-common-option.yaml
99
ref: session
10-
post: |
11-
.. versionadded:: 1.3
1210
---
1311
source:
1412
file: apiargs-MongoDBCollection-common-option.yaml
@@ -17,7 +15,13 @@ post: |
1715
This is not supported for server versions prior to 3.4 and will result in an
1816
exception at execution time if used.
1917
---
20-
source:
21-
file: apiargs-MongoDBCollection-common-option.yaml
22-
ref: dropTarget
18+
arg_name: option
19+
name: dropTarget
20+
type: boolean
21+
description: |
22+
If ``true``, ``mongod`` will drop the ``target`` of ``renameCollection`` prior
23+
to renaming the collection. The default value is ``false``.
24+
interface: phpmethod
25+
operation: ~
26+
optional: true
2327
...
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
arg_name: param
2+
name: $toNamespace
3+
type: string
4+
description: |
5+
The new namespace of the collection. If the new namespace specifies a
6+
different database, the command copies the collection to the new database
7+
and drops the source collection.
8+
interface: phpmethod
9+
operation: ~
10+
optional: false
11+
---
12+
source:
13+
file: apiargs-common-param.yaml
14+
ref: $options
15+
...

docs/includes/apiargs-MongoDBCollection-method-renameCollection-param.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
source:
2+
file: apiargs-common-option.yaml
3+
ref: session
4+
---
5+
source:
6+
file: apiargs-MongoDBDatabase-common-option.yaml
7+
ref: typeMap
8+
post: |
9+
This will be used for the returned command result document.
10+
---
11+
source:
12+
file: apiargs-MongoDBDatabase-common-option.yaml
13+
ref: writeConcern
14+
post: |
15+
This is not supported for server versions prior to 3.4 and will result in an
16+
exception at execution time if used.
17+
---
18+
arg_name: option
19+
name: dropTarget
20+
type: boolean
21+
description: |
22+
If ``true``, ``mongod`` will drop the ``target`` of ``renameCollection`` prior
23+
to renaming the collection. The default value is ``false``.
24+
interface: phpmethod
25+
operation: ~
26+
optional: true
27+
...
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
source:
2+
file: apiargs-common-param.yaml
3+
ref: $fromNamespace
4+
replacement:
5+
action: " to rename"
6+
---
7+
source:
8+
file: apiargs-common-param.yaml
9+
ref: $toNamespace
10+
replacement:
11+
action: ""
12+
---
13+
source:
14+
file: apiargs-common-param.yaml
15+
ref: $options
16+
...

docs/reference/method/MongoDBCollection-renameCollection.txt renamed to docs/reference/method/MongoDBCollection-rename.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
===========================
2-
MongoDB\\Collection::renameCollection()
3-
===========================
1+
=============================
2+
MongoDB\\Collection::rename()
3+
=============================
44

55
.. default-domain:: mongodb
66

@@ -13,21 +13,21 @@ MongoDB\\Collection::renameCollection()
1313
Definition
1414
----------
1515

16-
.. phpmethod:: MongoDB\\Collection::renameCollection()
16+
.. phpmethod:: MongoDB\\Collection::rename()
1717

1818
Rename the collection.
1919

2020
.. code-block:: php
2121

22-
function renameCollection(string $newCollectionName, array $options = []): array|object
22+
function rename(string $toNamespace, array $options = []): array|object
2323

2424
This method has the following parameters:
2525

26-
.. include:: /includes/apiargs/MongoDBCollection-method-renameCollection-param.rst
26+
.. include:: /includes/apiargs/MongoDBCollection-method-rename-param.rst
2727

2828
The ``$options`` parameter supports the following options:
2929

30-
.. include:: /includes/apiargs/MongoDBCollection-method-renameCollection-option.rst
30+
.. include:: /includes/apiargs/MongoDBCollection-method-rename-option.rst
3131

3232
Return Values
3333
-------------
@@ -46,16 +46,16 @@ Errors/Exceptions
4646
Example
4747
-------
4848

49-
The following operation renames the ``restaurants`` collection in the ``admin``
50-
database to ``zips``:
49+
The following operation renames the ``restaurants`` collection in the ``test``
50+
database to ``places``:
5151

5252
.. code-block:: php
5353

5454
<?php
5555

56-
$collection = (new MongoDB\Client)->admin->restaurants;
56+
$collection = (new MongoDB\Client)->test->restaurants;
5757

58-
$result = $collection->renameCollection('zips');
58+
$result = $collection->renameCollection('places');
5959

6060
var_dump($result);
6161

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
===================================
2+
MongoDB\\Database::renameCollection()
3+
===================================
4+
5+
.. default-domain:: mongodb
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
Definition
14+
----------
15+
16+
.. phpmethod:: MongoDB\\Database::renameCollection()
17+
18+
Changes the name of an existing collection.
19+
20+
.. code-block:: php
21+
22+
function renameCollection($fromNamespace, $toNamespace, array $options = []): array|object
23+
24+
This method has the following parameters:
25+
26+
.. include:: /includes/apiargs/MongoDBDatabase-method-renameCollection-param.rst
27+
28+
The ``$options`` parameter supports the following options:
29+
30+
.. include:: /includes/apiargs/MongoDBDatabase-method-renameCollection-option.rst
31+
32+
Return Values
33+
-------------
34+
35+
An array or object with the result document of the :manual:`renameCollection
36+
</reference/command/renameCollection>` command. The return type will depend on the
37+
``typeMap`` option.
38+
39+
Errors/Exceptions
40+
-----------------
41+
42+
.. include:: /includes/extracts/error-unsupportedexception.rst
43+
.. include:: /includes/extracts/error-invalidargumentexception.rst
44+
.. include:: /includes/extracts/error-driver-runtimeexception.rst
45+
46+
Example
47+
-------
48+
49+
The following example renames the ``users`` collection in the ``test`` database:
50+
51+
.. code-block:: php
52+
53+
<?php
54+
55+
$db = (new MongoDB\Client)->test;
56+
57+
$result = $db->renameCollection('users', 'restaurants');
58+
59+
var_dump($result);
60+
61+
The output would then resemble::
62+
63+
object(MongoDB\Model\BSONDocument)#8 (1) {
64+
["storage":"ArrayObject":private]=>
65+
array(3) {
66+
["ns"]=>
67+
string(10) "test.restaurants"
68+
["nIndexesWas"]=>
69+
int(1)
70+
["ok"]=>
71+
float(1)
72+
}
73+
}
74+
75+
See Also
76+
--------
77+
78+
- :phpmethod:`MongoDB\\Collection::rename()`
79+
- :manual:`renameCollection </reference/command/renameCollection>` command reference in the MongoDB
80+
manual

0 commit comments

Comments
 (0)