Skip to content

PHPLIB-675 Document new CollectionInfo methods #841

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 5 commits into from
Jul 13, 2021

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Jul 9, 2021

PHPLIB-675

Adds missing documentation for new method and documents the deprecation of helpers relating to capped collections.

@alcaeus alcaeus requested a review from jmikola July 9, 2021 07:31
@alcaeus alcaeus self-assigned this Jul 9, 2021
Comment on lines +37 to +48
$info = new CollectionInfo([
'type' => 'view',
'name' => 'foo',
'idIndex' => [
'v' => 2,
'key' => ['_id' => 1],
'name' => '_id',
'ns' => 'test.foo',
],
]);

var_dump($info->getIdIndex());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if these examples are really helpful. I believe we could optimise these by creating a collection first, then getting a CollectionInfo object for a collection and dumping from there. Right now, the example doesn't really clarify that the info here is server dependent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur. There's absolutely no reason to construct this directly, as that's not the intended use of this API.

It looks like these examples date back to PHPLIB-278, which I signed off on. In the meantime, I'd suggest not adding any new examples and making a ticket to either replace all of these with integration examples or remove them entirely and just point users to the corresponding enumeration method that would return these objects in the first place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave these examples in for consistency and have created PHPLIB-689 to track improvements.

@@ -29,6 +31,9 @@ Return Values
The size limit for the capped collection in bytes. If the collection is not
capped, ``null`` will be returned.

This method is deprecated in favor of using
:phpmethod:`MongoDB\\Model\\CollectionInfo::getOptions()`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here for suggesting folks access the size key.


.. code-block:: php

function getInfo(): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a thought about how this and getOptions cast the returned value to an array and how that might be inconsistent is a nested value was a document and was reported as a stdClass. I then remembered that ListCollections doesn't support a typeMap option at all and applies its own typeMap such that root and embedded docs become PHP arrays. So there's no reason to be concerned about inconsistency -- and I also don't worry about the MongoDB server returning a value that would be ambiguous (e.g. document with sequential numeric keys).

@alcaeus alcaeus requested a review from jmikola July 12, 2021 12:46
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting for deprecated methods need double backticks. LGTM otherwise.

@alcaeus alcaeus merged commit e98f22a into mongodb:master Jul 13, 2021
@alcaeus alcaeus deleted the phplib-675 branch July 13, 2021 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants