@@ -57,16 +57,13 @@ You can use Laravel's Eloquent object-relational mapper (ORM) to create models
5757that represent MongoDB collections and chain methods on them to specify
5858query criteria.
5959
60- To retrieve documents that match a set of criteria, pass a query filter to the
61- ``where()`` method.
60+ To retrieve documents that match a set of criteria, call the ``where()``
61+ method on the collection's corresponding Eloquent model, then pass a query
62+ filter to the method.
6263
6364A query filter specifies field value requirements and instructs the find
6465operation to return only documents that meet these requirements.
6566
66- You can use Laravel's Eloquent object-relational mapper (ORM) to create models
67- that represent MongoDB collections. To retrieve documents from a collection,
68- call the ``where()`` method on the collection's corresponding Eloquent model.
69-
7067You can use one of the following ``where()`` method calls to build a query:
7168
7269- ``where('<field name>', <value>)`` builds a query that matches documents in
@@ -79,7 +76,7 @@ You can use one of the following ``where()`` method calls to build a query:
7976To apply multiple sets of criteria to the find operation, you can chain a series
8077of ``where()`` methods together.
8178
82- After building your query with the ``where()`` method, chain the ``get()``
79+ After building your query by using the ``where()`` method, chain the ``get()``
8380method to retrieve the query results.
8481
8582This example calls two ``where()`` methods on the ``Movie`` Eloquent model to
@@ -150,6 +147,60 @@ retrieve documents that meet the following criteria:
150147To learn how to query by using the Laravel query builder instead of the
151148Eloquent ORM, see the :ref:`laravel-query-builder` page.
152149
150+ Match Array Field Elements
151+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
152+
153+ You can specify a query filter to match array field elements when
154+ retrieving documents. If your documents contain an array field, you can
155+ match documents based on if the value contains all or some specified
156+ array elements.
157+
158+ You can use one of the following ``where()`` method calls to build a
159+ query on an array field:
160+
161+ - ``where('<array field>', <array>)`` builds a query that matches documents in
162+ which the array field value is exactly the specified array
163+
164+ - ``where('<array field>', 'in', <array>)`` builds a query
165+ that matches documents in which the array field value contains one or
166+ more of the specified array elements
167+
168+ After building your query by using the ``where()`` method, chain the ``get()``
169+ method to retrieve the query results.
170+
171+ Select from the following :guilabel:`Exact Array Match` and
172+ :guilabel:`Element Match` tabs to view the query syntax for each pattern:
173+
174+ .. tabs::
175+
176+ .. tab:: Exact Array Match
177+ :tabid: exact-array
178+
179+ This example retrieves documents in which the ``countries`` array is
180+ exactly ``['Indonesia', 'Canada']``:
181+
182+ .. literalinclude:: /includes/fundamentals/read-operations/ReadOperationsTest.php
183+ :language: php
184+ :dedent:
185+ :start-after: start-exact-array
186+ :end-before: end-exact-array
187+
188+ .. tab:: Element Match
189+ :tabid: element-match
190+
191+ This example retrieves documents in which the ``countries`` array
192+ contains one of the values in the array ``['Canada', 'Egypt']``:
193+
194+ .. literalinclude:: /includes/fundamentals/read-operations/ReadOperationsTest.php
195+ :language: php
196+ :dedent:
197+ :start-after: start-elem-match
198+ :end-before: end-elem-match
199+
200+ To learn how to query array fields by using the Laravel query builder instead of the
201+ Eloquent ORM, see the :ref:`laravel-query-builder-elemMatch` section in
202+ the Query Builder guide.
203+
153204.. _laravel-retrieve-all:
154205
155206Retrieve All Documents in a Collection
@@ -200,7 +251,7 @@ by the ``$search`` field in your query filter that you pass to the
200251``where()`` method. The ``$text`` operator performs a text search on the
201252text-indexed fields. The ``$search`` field specifies the text to search for.
202253
203- After building your query with the ``where()`` method, chain the ``get()``
254+ After building your query by using the ``where()`` method, chain the ``get()``
204255method to retrieve the query results.
205256
206257This example calls the ``where()`` method on the ``Movie`` Eloquent model to
0 commit comments