Skip to content

PHPLIB-153: Add Database::command() helper #48

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

Closed
wants to merge 1 commit into from

Conversation

tuyakhov
Copy link
Contributor

https://jira.mongodb.org/browse/PHPLIB-153


Add method to issue database commands. According to legacy PHP driver. http://php.net/manual/ru/mongodb.command.php

I did not find any contribution conditions. Please let me know if I need to create seperate branches for this.

@tuyakhov tuyakhov changed the title add executeCommand method to Database Add new operation and executeCommand method Nov 15, 2015
@jmikola
Copy link
Member

jmikola commented Nov 16, 2015

@tuyakhov: Thanks for the PR. I'm on holiday this week, but I'll look into this when I get a chance and hopefully get it merged in the coming week (by Nov 24).

I did intend to add a method to execute generic commands on a Database before 1.0.0 but forgot to make a ticket for it. I'll do so now just to ensure we're tracking it in the changelog :)

@tuyakhov
Copy link
Contributor Author

@jmikola Thank you for quick reply. I'm waiting for your review.
Enjoy your holiday :)

@tuyakhov tuyakhov changed the title Add new operation and executeCommand method Add Group operation and executeCommand method Nov 25, 2015
@derickr
Copy link
Contributor

derickr commented Nov 26, 2015

Just pinging this to poke @jmikola :-)

@tuyakhov tuyakhov force-pushed the master branch 2 times, most recently from 00d2548 to c9091f8 Compare November 29, 2015 18:18
@tuyakhov
Copy link
Contributor Author

@jmikola Please let know if it could be merged in near future. Looks like CI failure is not related to my PR.

@@ -7,3 +7,4 @@ php.ini
phpunit.xml
apigen.phar
site
.idea
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove this. IDE-specific ignores are best left in users' own .gitignore files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I agree, it was unnecessary.

public function executeCommand(Command $command, ReadPreference $readPreference = null)
{
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
return $server->executeCommand($this->databaseName, $command, $readPreference);
Copy link
Member

Choose a reason for hiding this comment

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

I'll discuss this with @derickr this week, but I think we may want to change two things here:

  • The command document can be an array or object (i.e. a document), which we'll use to construct a Command instance internally. In the library, I don't think we need to require the driver value object to be used (for the convenience of users).
  • This appears to be hard-coded to select the primary server. I think we'll want to take an optional read preference and then use that to select the server, as we do in Collection::count().

Feel free to hold off on any changes until I follow up, though. I don't want to waste your time on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jmikola Please check updates

@tuyakhov tuyakhov changed the title Add Group operation and executeCommand method Add executeCommand method Dec 13, 2015
@jmikola
Copy link
Member

jmikola commented Dec 16, 2015

It is make sense especially if group could be deprecated. But if this library implements an API similar to that of the legacy PHP driver, may be it would be better to add this helper? Any way i removed this commit from current PR and created a separate branch for it.

I don't have any confirmation of it being deprecated, but there were internal discussions about not adding it to a new API. @alcaeus is actually working on a project that implements the legacy driver's API atop the new mongodb extension, so it would certainly have a place there.

@jmikola jmikola changed the title Add executeCommand method PHPLIB-153: Add Database::command() helper Dec 16, 2015
jmikola added a commit that referenced this pull request Dec 16, 2015
@jmikola
Copy link
Member

jmikola commented Dec 16, 2015

@tuyakhov: I merged this in 9d087e5. Some changes:

  • Renamed the helper method to command(), as that's what most other drivers are using for their helper.
  • Tweaked the exception message for the $command document argument.
  • Added a test case for an invalid $command argument

Thanks!

@jmikola jmikola closed this Dec 16, 2015
GromNaN added a commit to GromNaN/mongo-php-library that referenced this pull request Sep 9, 2024
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.

3 participants