Skip to content

Commit 316554c

Browse files
Merge 5.0 into 5.1 (#3214)
2 parents e6edd63 + c9b74e8 commit 316554c

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

docs/includes/query-builder/QueryBuilderTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ protected function tearDown(): void
4848
parent::tearDown();
4949
}
5050

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

docs/query-builder.txt

+37-6
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,16 @@ The following example shows the syntax of a query builder call:
5353

5454
.. tip:: Set Database Connection
5555

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

60-
If MongoDB is not your application's default database, you can use the ``DB::connection()`` method
61-
to specify a MongoDB connection. Pass the name of the connection to the ``connection()`` method,
62-
as shown in the following code:
62+
If MongoDB is not your application's default database, you can use
63+
the ``DB::connection()`` method to specify a MongoDB connection. Pass
64+
the name of the connection to the ``connection()`` method, as shown
65+
in the following code:
6366

6467
.. code-block:: php
6568

@@ -68,6 +71,7 @@ The following example shows the syntax of a query builder call:
6871
This guide provides examples of the following types of query builder operations:
6972

7073
- :ref:`laravel-retrieve-query-builder`
74+
- :ref:`laravel-options-query-builder`
7175
- :ref:`laravel-modify-results-query-builder`
7276
- :ref:`laravel-mongodb-read-query-builder`
7377
- :ref:`laravel-mongodb-write-query-builder`
@@ -654,6 +658,33 @@ value of ``imdb.rating`` of those matches by using the
654658
:start-after: begin aggregation with filter
655659
:end-before: end aggregation with filter
656660

661+
.. _laravel-options-query-builder:
662+
663+
Set Query-Level Options
664+
-----------------------
665+
666+
You can modify the way that the {+odm-short+} performs operations by
667+
setting options on the query builder. You can pass an array of options
668+
to the ``options()`` query builder method to specify options for the
669+
query.
670+
671+
The following code demonstrates how to attach a comment to
672+
a query:
673+
674+
.. literalinclude:: /includes/query-builder/QueryBuilderTest.php
675+
:language: php
676+
:dedent:
677+
:start-after: begin options
678+
:end-before: end options
679+
680+
The query builder accepts the same options that you can set for
681+
the :phpmethod:`find() <phpmethod.MongoDB\\Collection::find()>` method in the
682+
{+php-library+}. Some of the options to modify query results, such as
683+
``skip``, ``sort``, and ``limit``, are settable directly as query
684+
builder methods and are described in the
685+
:ref:`laravel-modify-results-query-builder` section of this guide. We
686+
recommend that you use these methods instead of passing them as options.
687+
657688
.. _laravel-modify-results-query-builder:
658689

659690
Modify Query Results

0 commit comments

Comments
 (0)