Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 4.8 into 5.0 #3213

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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