Skip to content

Commit c038ed8

Browse files
committed
DOCSP-45411: qb options
1 parent 05a090b commit c038ed8

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

docs/includes/query-builder/QueryBuilderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ protected function tearDown(): void
4646
parent::tearDown();
4747
}
4848

49+
public function testOptions(): void
50+
{
51+
// begin options
52+
$result = DB::connection('mongodb')
53+
->table('movies')
54+
->where('year', 2000)
55+
->options(['comment' => 'hello'])
56+
->get();
57+
// end options
58+
59+
$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
60+
}
61+
4962
public function testWhere(): void
5063
{
5164
// begin query where

docs/query-builder.txt

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,27 @@ The following example shows the syntax of a query builder call:
4646
DB::table('<collection name>')
4747
// chain methods by using the "->" object operator
4848
->get();
49+
4950
.. tip::
5051

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

55-
If MongoDB is not your application's default database, you can use the ``DB::connection()`` method
56-
to specify a MongoDB connection. Pass the name of the connection to the ``connection()`` method,
57-
as shown in the following code:
58+
If MongoDB is not your application's default database, you can use
59+
the ``DB::connection()`` method to specify a MongoDB connection. Pass
60+
the name of the connection to the ``connection()`` method, as shown
61+
in the following code:
5862

5963
.. code-block:: php
6064

6165
$connection = DB::connection('mongodb');
6266

6367
This guide provides examples of the following types of query builder operations:
6468

69+
- :ref:`laravel-options-query-builder`
6570
- :ref:`laravel-retrieve-query-builder`
6671
- :ref:`laravel-modify-results-query-builder`
6772
- :ref:`laravel-mongodb-read-query-builder`
@@ -81,6 +86,33 @@ of the Quick Start.
8186
To perform read and write operations by using the query builder, import the
8287
``Illuminate\Support\Facades\DB`` facade and compose your query.
8388

89+
.. _laravel-options-query-builder:
90+
91+
Set Query-Level Options
92+
-----------------------
93+
94+
You can modify the way that the {+odm-short+} performs queries by
95+
setting options on the query builder. You can pass an array of options
96+
to the ``options()`` query builder method to specify options for the
97+
query.
98+
99+
The following code demonstrates how to attach a comment to
100+
a query:
101+
102+
.. literalinclude:: /includes/query-builder/QueryBuilderTest.php
103+
:language: php
104+
:dedent:
105+
:start-after: begin options
106+
:end-before: end options
107+
108+
The query builder accepts the same options that you can set for
109+
the :phpmethod:`MongoDB\Collection::find()` method in the
110+
{+php-library+}. Some of the options to modify query results, such as
111+
``skip``, ``sort``, and ``limit``, are settable directly as query
112+
builder methods and are described in the
113+
:ref:`laravel-modify-results-query-builder` section of this guide. We
114+
recommend that you use these methods instead of passing them as options.
115+
84116
.. _laravel-retrieve-query-builder:
85117

86118
Retrieve Matching Documents

0 commit comments

Comments
 (0)