@@ -46,22 +46,27 @@ The following example shows the syntax of a query builder call:
46
46
DB::table('<collection name>')
47
47
// chain methods by using the "->" object operator
48
48
->get();
49
+
49
50
.. tip::
50
51
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.
54
57
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:
58
62
59
63
.. code-block:: php
60
64
61
65
$connection = DB::connection('mongodb');
62
66
63
67
This guide provides examples of the following types of query builder operations:
64
68
69
+ - :ref:`laravel-options-query-builder`
65
70
- :ref:`laravel-retrieve-query-builder`
66
71
- :ref:`laravel-modify-results-query-builder`
67
72
- :ref:`laravel-mongodb-read-query-builder`
@@ -81,6 +86,33 @@ of the Quick Start.
81
86
To perform read and write operations by using the query builder, import the
82
87
``Illuminate\Support\Facades\DB`` facade and compose your query.
83
88
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
+
84
116
.. _laravel-retrieve-query-builder:
85
117
86
118
Retrieve Matching Documents
0 commit comments