-
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
Conversation
docs/includes/apiargs-MongoDBCollection-method-renameCollection-option.yaml
Outdated
Show resolved
Hide resolved
docs/includes/apiargs-MongoDBCollection-method-renameCollection-option.yaml
Outdated
Show resolved
Hide resolved
docs/includes/apiargs-MongoDBCollection-method-renameCollection-option.yaml
Outdated
Show resolved
Hide resolved
docs/includes/apiargs-MongoDBCollection-method-renameCollection-param.yaml
Outdated
Show resolved
Hide resolved
docs/includes/apiargs-MongoDBCollection-method-renameCollection-param.yaml
Outdated
Show resolved
Hide resolved
|
||
.. code-block:: php | ||
|
||
function renameCollection($fromNamespace, $toNamespace, array $options = []): array|object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few suggestions:
$fromNamespace
can be$collectionName
. Since we already have the context of a database, it makes sense that only the collection name would be dynamic. Omitting a "from" prefix will allow us to re-use the same include asdropCollection()
's docs.$toNamespace
can be$toCollectionNameOrNamespace
. I'd propose we accept either as a convenience. If the argument doesn't include a dot, we can prefix the value with the current database name and a dot before passing it along to the RenameCollection operation. Docs for this param can be the same as theCollection::rename()
suggestion I shared above.
This handles the general use case where someone may want to rename collections within the same database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmikola I don't think it works to determine whether a collection name or namespace is being provided by checking whether the argument contains a dot, since the collection names used in the tests contain a dot as well. So I'm not sure how it would be possible to do this actually - any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good point. This would work the other way around (e.g. $databaseNameOrNamespace
) because database names cannot contain dots; however, it's ambiguous if we're trying to differentiate a namespace from a collection name.
In that case, I think it makes sense to leave $toNamespace
as-is.
$fromNamespace
can still be changed to $collectionName
for consistency with Database::dropCollection()
, and the helper method can build the namespace to send to the Operation internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add on to this, let's change the API of both the helpers and Operation class to no longer take namespace strings as paramaters:
$database->renameCollection($collectionName, $toDatabaseName, $toCollectionName);
$collection->rename($toDatabaseName, $toCollectionName);
The Operation class will then have four required parameters:
- fromDatabaseName
- fromCollectionName
- toDatabaseName
- toCollectionName
It can then build the namespace internally with string concatenation in the constructor (allowing you to keep the internal private properties that store namespaces).
For the Database helper, fromDatabaseName would be pulled from the database instance's own name. And for the Collection helper, both "from" parameters would be pulled from the collection instance.
docs/includes/apiargs-MongoDBDatabase-method-renameCollection-param.yaml
Outdated
Show resolved
Hide resolved
docs/includes/apiargs-MongoDBDatabase-method-renameCollection-option.yaml
Outdated
Show resolved
Hide resolved
docs/includes/apiargs-MongoDBCollection-method-rename-option.yaml
Outdated
Show resolved
Hide resolved
…ollectionFunctionalTest
…unctionalTestCase
cb6947a
to
9fcabfa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed the code files but skipped the docs on this round. I'll come back to those on Friday and do a local build to check for any RST errors.
Co-authored-by: Jeremy Mikola <jmikola@gmail.com> Co-authored-by: Jeremy Mikola <jmikola@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Built the documentation locally and didn't see any syntax errors. Left one suggestion to reword, and then some other suggestions for outstanding comments on code docs.
docs/includes/apiargs-MongoDBCollection-method-rename-param.yaml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests appear to be passing, which confirms that the earlier issue was unrelated.
LGTM after a few doc block suggestions.
When squashing and merging this, I'd suggest the following description.
Most of the other commit messages shouldn't be relevant, and this summarizes the actual changes we might want to look back on down the line. You can also rename the PR itself to "PHPLIB-518: RenameCollection operation", which should suggest that title when squashing. |
Co-authored-by: Jeremy Mikola <jmikola@gmail.com>
https://jira.mongodb.org/browse/PHPLIB-518