@@ -46,15 +46,19 @@ 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
@@ -63,6 +67,7 @@ The following example shows the syntax of a query builder call:
63
67
This guide provides examples of the following types of query builder operations:
64
68
65
69
- :ref:`laravel-retrieve-query-builder`
70
+ - :ref:`laravel-options-query-builder`
66
71
- :ref:`laravel-modify-results-query-builder`
67
72
- :ref:`laravel-mongodb-read-query-builder`
68
73
- :ref:`laravel-mongodb-write-query-builder`
@@ -606,6 +611,33 @@ value of ``imdb.rating`` of those matches by using the
606
611
:start-after: begin aggregation with filter
607
612
:end-before: end aggregation with filter
608
613
614
+ .. _laravel-options-query-builder:
615
+
616
+ Set Query-Level Options
617
+ -----------------------
618
+
619
+ You can modify the way that the {+odm-short+} performs operations by
620
+ setting options on the query builder. You can pass an array of options
621
+ to the ``options()`` query builder method to specify options for the
622
+ query.
623
+
624
+ The following code demonstrates how to attach a comment to
625
+ a query:
626
+
627
+ .. literalinclude:: /includes/query-builder/QueryBuilderTest.php
628
+ :language: php
629
+ :dedent:
630
+ :start-after: begin options
631
+ :end-before: end options
632
+
633
+ The query builder accepts the same options that you can set for
634
+ the :phpmethod:`find() <phpmethod.MongoDB\\Collection::find()>` method in the
635
+ {+php-library+}. Some of the options to modify query results, such as
636
+ ``skip``, ``sort``, and ``limit``, are settable directly as query
637
+ builder methods and are described in the
638
+ :ref:`laravel-modify-results-query-builder` section of this guide. We
639
+ recommend that you use these methods instead of passing them as options.
640
+
609
641
.. _laravel-modify-results-query-builder:
610
642
611
643
Modify Query Results
0 commit comments