-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-518: Provide MongoDB\Collection::rename() method to rename a collection #840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
cd0a73f
PHPLIB-518: Provide MongoDB\Collection::rename() method to rename a c…
tanlisu 8a150d8
Add testRenameCollection()
tanlisu 40eede4
Add documentation
tanlisu a58af56
Fix coding standard errors
tanlisu c87f320
Use namespace instead of collectionName for renameCollection
tanlisu 4687c97
Fix RenameCollectionFunctionalTest
tanlisu eca501a
Rename sourceNamespace, targetNamespace to fromNamespace, toNamespace
tanlisu 11a7693
Change Collection::renameCollection to Collection::rename(), update C…
tanlisu b65f1cb
Update renameCollection documentation
tanlisu a387972
Move assertCollectionDoesNotExist() and assertCollectionExists() to F…
tanlisu c1da777
Add testRenameCollection() to DatabaseFunctionalTest
tanlisu 9b9745f
Update rename documentation, fix coding standard errors
tanlisu 63f7dff
Update RenameCollectionTest
tanlisu 9b06329
Update renameCollection API
tanlisu c57c745
Update renameCollection documentation
tanlisu b68e287
Update $databaseName arg in calls to assertCollectionExists()
tanlisu 8762274
Update RenameCollectionTest
tanlisu 93cef46
Fix tests for renaming collection to different database
tanlisu 0db017c
Fix evergreen error
tanlisu 796fae3
Apply suggestions from code review
tanlisu 6793cce
Update rename tests for sharded cluster
tanlisu fe5d64d
Update documentation
tanlisu cc4e663
Apply suggestions from code review
tanlisu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
docs/includes/apiargs-MongoDBCollection-method-rename-option.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
source: | ||
file: apiargs-MongoDBCollection-common-option.yaml | ||
ref: typeMap | ||
post: | | ||
This will be used for the returned command result document. | ||
--- | ||
source: | ||
file: apiargs-common-option.yaml | ||
ref: session | ||
--- | ||
source: | ||
file: apiargs-MongoDBCollection-common-option.yaml | ||
ref: writeConcern | ||
post: | | ||
This is not supported for server versions prior to 3.4 and will result in an | ||
exception at execution time if used. | ||
--- | ||
arg_name: option | ||
name: dropTarget | ||
type: boolean | ||
description: | | ||
If ``true``, MongoDB will drop the target before renaming the collection. The | ||
default value is ``false``. | ||
interface: phpmethod | ||
operation: ~ | ||
optional: true | ||
... |
25 changes: 25 additions & 0 deletions
25
docs/includes/apiargs-MongoDBCollection-method-rename-param.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
arg_name: param | ||
name: $toCollectionName | ||
type: string | ||
description: | | ||
The new name of the collection. | ||
interface: phpmethod | ||
operation: ~ | ||
optional: false | ||
--- | ||
arg_name: param | ||
name: $toDatabaseName | ||
type: string | ||
description: | | ||
The new database name of the collection. If a new database name is not | ||
specified, the database of the original collection will be used. If the new | ||
name specifies a different database, the command copies the collection | ||
to the new database and drops the source collection. | ||
interface: phpmethod | ||
operation: ~ | ||
optional: true | ||
--- | ||
source: | ||
file: apiargs-common-param.yaml | ||
ref: $options | ||
... |
27 changes: 27 additions & 0 deletions
27
docs/includes/apiargs-MongoDBDatabase-method-renameCollection-option.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
source: | ||
file: apiargs-common-option.yaml | ||
ref: session | ||
--- | ||
source: | ||
file: apiargs-MongoDBDatabase-common-option.yaml | ||
ref: typeMap | ||
post: | | ||
This will be used for the returned command result document. | ||
--- | ||
source: | ||
file: apiargs-MongoDBDatabase-common-option.yaml | ||
ref: writeConcern | ||
post: | | ||
This is not supported for server versions prior to 3.4 and will result in an | ||
exception at execution time if used. | ||
--- | ||
arg_name: option | ||
name: dropTarget | ||
type: boolean | ||
description: | | ||
If ``true``, MongoDB will drop the target before renaming the collection. The | ||
default value is ``false``. | ||
interface: phpmethod | ||
operation: ~ | ||
optional: true | ||
... |
34 changes: 34 additions & 0 deletions
34
docs/includes/apiargs-MongoDBDatabase-method-renameCollection-param.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
arg_name: param | ||
name: $fromCollectionName | ||
type: string | ||
description: | | ||
The name of the collection to rename. | ||
interface: phpmethod | ||
operation: ~ | ||
optional: false | ||
--- | ||
arg_name: param | ||
name: $toCollectionName | ||
type: string | ||
description: | | ||
The new name of the collection. | ||
interface: phpmethod | ||
operation: ~ | ||
optional: false | ||
--- | ||
arg_name: param | ||
name: $toDatabaseName | ||
type: string | ||
description: | | ||
The new database name of the collection. If a new database name is not | ||
specified, the current database will be used. If the new name specifies a | ||
different database, the command copies the collection to the new database | ||
and drops the source collection. | ||
interface: phpmethod | ||
operation: ~ | ||
optional: true | ||
--- | ||
source: | ||
file: apiargs-common-param.yaml | ||
ref: $options | ||
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
============================= | ||
MongoDB\\Collection::rename() | ||
============================= | ||
|
||
.. versionadded:: 1.10 | ||
|
||
.. default-domain:: mongodb | ||
tanlisu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 1 | ||
:class: singlecol | ||
|
||
Definition | ||
---------- | ||
|
||
.. phpmethod:: MongoDB\\Collection::rename() | ||
|
||
Rename the collection. | ||
|
||
.. code-block:: php | ||
|
||
function rename(string $toCollectionName, ?string $toDatabaseName = null, array $options = []): array|object | ||
|
||
This method has the following parameters: | ||
|
||
.. include:: /includes/apiargs/MongoDBCollection-method-rename-param.rst | ||
|
||
The ``$options`` parameter supports the following options: | ||
|
||
.. include:: /includes/apiargs/MongoDBCollection-method-rename-option.rst | ||
|
||
Return Values | ||
------------- | ||
|
||
An array or object with the result document of the :manual:`renameCollection | ||
</reference/command/renameCollection>` command. The return type will depend on the | ||
``typeMap`` option. | ||
|
||
Errors/Exceptions | ||
----------------- | ||
|
||
.. include:: /includes/extracts/error-unsupportedexception.rst | ||
.. include:: /includes/extracts/error-invalidargumentexception.rst | ||
.. include:: /includes/extracts/error-driver-runtimeexception.rst | ||
|
||
Example | ||
------- | ||
|
||
The following operation renames the ``restaurants`` collection in the ``test`` | ||
database to ``places``: | ||
|
||
.. code-block:: php | ||
|
||
<?php | ||
|
||
$collection = (new MongoDB\Client)->test->restaurants; | ||
|
||
$result = $collection->rename('places'); | ||
|
||
var_dump($result); | ||
|
||
The output would then resemble:: | ||
|
||
object(MongoDB\Model\BSONDocument)#9 (1) { | ||
["storage":"ArrayObject":private]=> | ||
array(1) { | ||
["ok"]=> | ||
float(1) | ||
} | ||
} | ||
tanlisu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
See Also | ||
-------- | ||
|
||
- :phpmethod:`MongoDB\\Database::renameCollection()` | ||
- :manual:`renameCollection </reference/command/renameCollection>` command reference in the MongoDB | ||
manual |
79 changes: 79 additions & 0 deletions
79
docs/reference/method/MongoDBDatabase-renameCollection.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
===================================== | ||
MongoDB\\Database::renameCollection() | ||
===================================== | ||
|
||
.. versionadded:: 1.10 | ||
|
||
.. default-domain:: mongodb | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 1 | ||
:class: singlecol | ||
|
||
Definition | ||
---------- | ||
|
||
.. phpmethod:: MongoDB\\Database::renameCollection() | ||
|
||
Rename a collection within the current database. | ||
|
||
.. code-block:: php | ||
|
||
function renameCollection(string $fromCollectionName, string $toCollectionName, ?string $toDatabaseName = null, array $options = []): array|object | ||
|
||
This method has the following parameters: | ||
|
||
.. include:: /includes/apiargs/MongoDBDatabase-method-renameCollection-param.rst | ||
|
||
The ``$options`` parameter supports the following options: | ||
|
||
.. include:: /includes/apiargs/MongoDBDatabase-method-renameCollection-option.rst | ||
|
||
Return Values | ||
------------- | ||
|
||
An array or object with the result document of the :manual:`renameCollection | ||
</reference/command/renameCollection>` command. The return type will depend on the | ||
``typeMap`` option. | ||
|
||
Errors/Exceptions | ||
----------------- | ||
|
||
.. include:: /includes/extracts/error-unsupportedexception.rst | ||
.. include:: /includes/extracts/error-invalidargumentexception.rst | ||
.. include:: /includes/extracts/error-driver-runtimeexception.rst | ||
|
||
Example | ||
------- | ||
|
||
The following example renames the ``restaurants`` collection in the ``test`` | ||
database to ``places``: | ||
|
||
.. code-block:: php | ||
|
||
<?php | ||
|
||
$db = (new MongoDB\Client)->test; | ||
|
||
$result = $db->renameCollection('restaurants', 'places'); | ||
|
||
var_dump($result); | ||
|
||
The output would then resemble:: | ||
|
||
object(MongoDB\Model\BSONDocument)#8 (1) { | ||
["storage":"ArrayObject":private]=> | ||
array(1) { | ||
["ok"]=> | ||
float(1) | ||
} | ||
} | ||
|
||
See Also | ||
-------- | ||
|
||
- :phpmethod:`MongoDB\\Collection::rename()` | ||
- :manual:`renameCollection </reference/command/renameCollection>` command reference in the MongoDB | ||
manual |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.