Skip to content

Commit

Permalink
DOCSP-45411: qb options (#3208)
Browse files Browse the repository at this point in the history
* DOCSP-45411: qb options

* link

* NR PR fixes 1
  • Loading branch information
rustagir authored Nov 20, 2024
1 parent da3a46a commit 0af5611
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
13 changes: 13 additions & 0 deletions docs/includes/query-builder/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ protected function tearDown(): void
parent::tearDown();
}

public function testOptions(): void
{
// begin options
$result = DB::connection('mongodb')
->table('movies')
->where('year', 2000)
->options(['comment' => 'hello'])
->get();
// end options

$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
}

public function testWhere(): void
{
// begin query where
Expand Down
44 changes: 38 additions & 6 deletions docs/query-builder.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ The following example shows the syntax of a query builder call:
DB::table('<collection name>')
// chain methods by using the "->" object operator
->get();

.. tip::

Before using the ``DB::table()`` method, ensure that you specify MongoDB as your application's
default database connection. For instructions on setting the database connection,
see the :ref:`laravel-quick-start-connect-to-mongodb` step in the Quick Start.
Before using the ``DB::table()`` method, ensure that you specify
MongoDB as your application's default database connection. For
instructions on setting the database connection, see the
:ref:`laravel-quick-start-connect-to-mongodb` step in the Quick
Start.

If MongoDB is not your application's default database, you can use the ``DB::connection()`` method
to specify a MongoDB connection. Pass the name of the connection to the ``connection()`` method,
as shown in the following code:
If MongoDB is not your application's default database, you can use
the ``DB::connection()`` method to specify a MongoDB connection. Pass
the name of the connection to the ``connection()`` method, as shown
in the following code:

.. code-block:: php

Expand All @@ -63,6 +67,7 @@ The following example shows the syntax of a query builder call:
This guide provides examples of the following types of query builder operations:

- :ref:`laravel-retrieve-query-builder`
- :ref:`laravel-options-query-builder`
- :ref:`laravel-modify-results-query-builder`
- :ref:`laravel-mongodb-read-query-builder`
- :ref:`laravel-mongodb-write-query-builder`
Expand Down Expand Up @@ -606,6 +611,33 @@ value of ``imdb.rating`` of those matches by using the
:start-after: begin aggregation with filter
:end-before: end aggregation with filter

.. _laravel-options-query-builder:

Set Query-Level Options
-----------------------

You can modify the way that the {+odm-short+} performs operations by
setting options on the query builder. You can pass an array of options
to the ``options()`` query builder method to specify options for the
query.

The following code demonstrates how to attach a comment to
a query:

.. literalinclude:: /includes/query-builder/QueryBuilderTest.php
:language: php
:dedent:
:start-after: begin options
:end-before: end options

The query builder accepts the same options that you can set for
the :phpmethod:`find() <phpmethod.MongoDB\\Collection::find()>` method in the
{+php-library+}. Some of the options to modify query results, such as
``skip``, ``sort``, and ``limit``, are settable directly as query
builder methods and are described in the
:ref:`laravel-modify-results-query-builder` section of this guide. We
recommend that you use these methods instead of passing them as options.

.. _laravel-modify-results-query-builder:

Modify Query Results
Expand Down

0 comments on commit 0af5611

Please sign in to comment.