-
Notifications
You must be signed in to change notification settings - Fork 1.5k
DOCSP-35983: Run command usage example #2852
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
Changes from 5 commits
bb7af03
822e37d
c87fa9b
3f059be
937db89
322fdb0
0771a82
572ca04
b0f0e53
bc68863
e17ea5e
29b8d2c
2219d45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use MongoDB\Driver\Cursor; | ||
use MongoDB\Laravel\Tests\TestCase; | ||
|
||
class RunCommandTest extends TestCase | ||
{ | ||
/** | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
*/ | ||
public function testRunCommand(): void | ||
{ | ||
// begin-command | ||
$cursor = DB::connection('mongodb') | ||
->command(['listCollections' => 1]); | ||
|
||
foreach ($cursor as $coll) { | ||
echo $coll['name'] . '<br>'; | ||
} | ||
|
||
// end-command | ||
|
||
$this->assertNotNull($cursor); | ||
$this->assertInstanceOf(Cursor::class, $cursor); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,52 @@ | ||||||||
.. _laravel-run-command-usage: | ||||||||
|
||||||||
============= | ||||||||
Run a Command | ||||||||
============= | ||||||||
|
||||||||
You can run a command directly on a database by calling the ``command()`` | ||||||||
method on a database connection instance. | ||||||||
|
||||||||
To run a command, call the ``command()`` method and specify the database command | ||||||||
document inside the method call. This document includes the command name and | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: I think "database command document" might not be a common term, so avoiding it could also avoid having to provide the explanation in the next sentence.
Suggested change
|
||||||||
value. | ||||||||
|
||||||||
Example | ||||||||
------- | ||||||||
|
||||||||
This usage example performs the following actions: | ||||||||
|
||||||||
- Creates a database connection instance to access the ``sample_mflix`` database | ||||||||
- Specifies a command to retrieve a list of collections in the ``sample_mflix`` database | ||||||||
- Prints the name of each ``sample_mflix`` collection | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue: There's no reference to "sample_mflix" in the code example. Suggestion: I think it could be good to either describe as the database configured for your "mongodb" connection or to add some information before this list that mentions that the mongodb connection is set to sample_mflix. |
||||||||
|
||||||||
The example calls the ``command()`` method to run the ``listCollections`` command. This method | ||||||||
returns a cursor that contains a result document for each collection in the database. | ||||||||
|
||||||||
.. io-code-block:: | ||||||||
|
||||||||
.. input:: ../includes/usage-examples/RunCommandTest.php | ||||||||
:start-after: begin-command | ||||||||
:end-before: end-command | ||||||||
:language: php | ||||||||
:dedent: | ||||||||
|
||||||||
.. output:: | ||||||||
:language: console | ||||||||
:visible: false | ||||||||
|
||||||||
sessions | ||||||||
movies | ||||||||
theaters | ||||||||
comments | ||||||||
embedded_movies | ||||||||
users | ||||||||
|
||||||||
|
||||||||
To learn how to edit your Laravel application to run the usage example, see the | ||||||||
:ref:`Usage Examples landing page <laravel-usage-examples>`. | ||||||||
|
||||||||
.. tip:: | ||||||||
|
||||||||
To learn more about running MongoDB database commands, see | ||||||||
:manual:`Database Commands </reference/command/>` in the {+server-docs-name+}. |
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.
Suggestion:
I think it could be helpful to specify that it's a MongoDB command to avoid confusion, similar to how it's used in the admonition at the end of the page.