Skip to content

Commit 6c5dff2

Browse files
authored
DOCSP-36792: Add default database connection admonition (#2888)
Adds an admonition that advises users to set their default database connection to MongoDB
1 parent 6ac2b6a commit 6c5dff2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/query-builder.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ The following example shows the syntax of a query builder call:
4646
DB::collection('<collection name>')
4747
// chain methods by using the "->" object operator
4848
->get();
49+
.. tip::
50+
51+
Before using the ``DB::collection()`` 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.
54+
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+
59+
.. code-block:: php
60+
61+
$connection = DB::connection('mongodb');
4962

5063
This guide provides examples of the following types of query builder operations:
5164

0 commit comments

Comments
 (0)