Skip to content

Commit c57c745

Browse files
committed
Update renameCollection documentation
1 parent 9b06329 commit c57c745

7 files changed

+63
-27
lines changed

docs/includes/apiargs-MongoDBCollection-method-rename-option.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ arg_name: option
1919
name: dropTarget
2020
type: boolean
2121
description: |
22-
If ``true``, ``mongod`` will drop the ``target`` of ``renameCollection`` prior
23-
to renaming the collection. The default value is ``false``.
22+
If ``true``, MongoDB will drop the target before renaming the collection. The
23+
default value is ``false``.
2424
interface: phpmethod
2525
operation: ~
2626
optional: true

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
arg_name: param
2-
name: $toNamespace
2+
name: $toCollectionName
33
type: string
44
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.
5+
The new name of the collection. If a full namespace is not
6+
specified, the database of the original collection will be used. If the new
7+
namespace specifies a different database, the command copies the collection
8+
to the new database and drops the source collection.
89
interface: phpmethod
910
operation: ~
1011
optional: false
1112
---
13+
arg_name: param
14+
name: $toDatabaseName
15+
type: string
16+
description: |
17+
The new database name of the collection. If a new database name is not
18+
specified, the database of the original collection will be used. If the new
19+
name specifies a different database, the command copies the collection
20+
to the new database and drops the source collection.
21+
interface: phpmethod
22+
operation: ~
23+
optional: true
24+
---
1225
source:
1326
file: apiargs-common-param.yaml
1427
ref: $options

docs/includes/apiargs-MongoDBDatabase-method-renameCollection-option.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ arg_name: option
1919
name: dropTarget
2020
type: boolean
2121
description: |
22-
If ``true``, ``mongod`` will drop the ``target`` of ``renameCollection`` prior
23-
to renaming the collection. The default value is ``false``.
22+
If ``true``, MongoDB will drop the target before renaming the collection. The
23+
default value is ``false``.
2424
interface: phpmethod
2525
operation: ~
2626
optional: true

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

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1-
source:
2-
file: apiargs-common-param.yaml
3-
ref: $fromNamespace
4-
replacement:
5-
action: " to rename"
1+
arg_name: param
2+
name: $fromCollectionName
3+
type: string
4+
description: |
5+
The name of the collection to rename.
6+
interface: phpmethod
7+
operation: ~
8+
optional: false
69
---
7-
source:
8-
file: apiargs-common-param.yaml
9-
ref: $toNamespace
10-
replacement:
11-
action: ""
10+
arg_name: param
11+
name: $toCollectionName
12+
type: string
13+
description: |
14+
The new name of the collection.
15+
interface: phpmethod
16+
operation: ~
17+
optional: false
18+
---
19+
arg_name: param
20+
name: $toDatabaseName
21+
type: string
22+
description: |
23+
The new database name of the collection. If a new database name is not
24+
specified, the current database will be used. If the new name specifies a
25+
different database, the command copies the collection to the new database
26+
and drops the source collection.
27+
interface: phpmethod
28+
operation: ~
29+
optional: true
1230
---
1331
source:
1432
file: apiargs-common-param.yaml

docs/reference/class/MongoDBCollection.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Methods
9191
/reference/method/MongoDBCollection-insertOne
9292
/reference/method/MongoDBCollection-listIndexes
9393
/reference/method/MongoDBCollection-mapReduce
94-
/reference/method/MongoDBCollection-renameCollection
94+
/reference/method/MongoDBCollection-rename
9595
/reference/method/MongoDBCollection-replaceOne
9696
/reference/method/MongoDBCollection-updateMany
9797
/reference/method/MongoDBCollection-updateOne

docs/reference/method/MongoDBCollection-rename.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
MongoDB\\Collection::rename()
33
=============================
44

5+
.. versionadded:: 1.9
6+
57
.. default-domain:: mongodb
68

79
.. contents:: On this page
@@ -19,7 +21,7 @@ Definition
1921

2022
.. code-block:: php
2123

22-
function rename(string $toNamespace, array $options = []): array|object
24+
function rename(string $toCollectionName, ?string $toDatabaseName = null, array $options = []): array|object
2325

2426
This method has the following parameters:
2527

@@ -55,7 +57,7 @@ database to ``places``:
5557

5658
$collection = (new MongoDB\Client)->test->restaurants;
5759

58-
$result = $collection->renameCollection('places');
60+
$result = $collection->rename('places');
5961

6062
var_dump($result);
6163

docs/reference/method/MongoDBDatabase-renameCollection.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
===================================
1+
=====================================
22
MongoDB\\Database::renameCollection()
3-
===================================
3+
=====================================
4+
5+
.. versionadded:: 1.9
46

57
.. default-domain:: mongodb
68

@@ -15,11 +17,11 @@ Definition
1517

1618
.. phpmethod:: MongoDB\\Database::renameCollection()
1719

18-
Changes the name of an existing collection.
20+
Rename a collection within the current database.
1921

2022
.. code-block:: php
2123

22-
function renameCollection($fromNamespace, $toNamespace, array $options = []): array|object
24+
function renameCollection(string $fromCollectionName, string $toCollectionName, ?string $toDatabaseName = null, array $options = []): array|object
2325

2426
This method has the following parameters:
2527

@@ -46,15 +48,16 @@ Errors/Exceptions
4648
Example
4749
-------
4850

49-
The following example renames the ``users`` collection in the ``test`` database:
51+
The following example renames the ``restaurants`` collection in the ``test``
52+
database to ``places``:
5053

5154
.. code-block:: php
5255

5356
<?php
5457

5558
$db = (new MongoDB\Client)->test;
5659

57-
$result = $db->renameCollection('users', 'restaurants');
60+
$result = $db->renameCollection('restaurants', 'places');
5861

5962
var_dump($result);
6063

0 commit comments

Comments
 (0)