@@ -90,18 +90,19 @@ Create a Filter
90
90
---------------
91
91
92
92
You can use factory methods from the ``Query`` builder class to create
93
- filter definitions to use in find, update, and delete operations. To
94
- learn more about creating filters, see the :ref:`php-specify-query` guide.
93
+ filter definitions to use in find, update, and delete operations. When
94
+ using the ``Query::query()`` factory method to create queries, you can
95
+ use named argument syntax and implement type safety. To learn more about
96
+ creating filters, see the :ref:`php-specify-query` guide.
95
97
96
98
The following steps describe how to create a filter definition by using
97
99
builders:
98
100
99
- 1. Instantiate the ``QueryInterface`` by calling the ``Query::query()``
100
- method.
101
+ 1. Call the ``Query::query()`` method to create a query.
101
102
102
103
#. Pass the field name to filter on and a factory method from the
103
104
``Query`` class. You can pass one or more pairs of field names and
104
- criteria to the ``QueryInterface`` .
105
+ criteria in the filter to apply multiple clauses .
105
106
106
107
The following code shows the template to create a filter definition by
107
108
using builders:
@@ -114,6 +115,21 @@ using builders:
114
115
...
115
116
);
116
117
118
+ To combine query criteria by using logical query operators
119
+ (``$and``, ``$or``, ``$not``, ``$nor``), you can use the following
120
+ query template:
121
+
122
+ .. code-block:: php
123
+
124
+ $filter = Query::<logical operator>(
125
+ Query::query(<field name>: Query::<factory method>(<parameters>)),
126
+ Query::query(<field name>: Query::<factory method>(<parameters>)),
127
+ ...
128
+ );
129
+
130
+ To learn more, see :manual:`Logical Query Operators
131
+ </reference/operator/query-logical/>` in the {+mdb-server+} manual.
132
+
117
133
The following sections provide examples that use builders to create
118
134
filter definitions for different operations.
119
135
@@ -156,10 +172,18 @@ Delete Example
156
172
157
173
This example performs the following actions:
158
174
159
- - Uses the ``Query::regex()`` factory method to match documents in which
160
- the ``feature_type`` field value contains the string ``'nondangerous'``
175
+ - Uses the ``Query::or()`` factory method to match documents that
176
+ satisfy the either of the following query clauses:
177
+
178
+ - Clause that uses the ``Query::regex()`` factory method to check if
179
+ the ``feature_type`` field value contains the string ``'nondangerous'``
180
+
181
+ - Clause that uses the ``Query::gt()`` factory method to check if the
182
+ ``depth`` field value is greater than ``10.0``
183
+
161
184
- Calls the :phpmethod:`MongoDB\Collection::deleteOne()`
162
185
method to delete the first matching document
186
+
163
187
- Prints the number of deleted documents
164
188
165
189
.. io-code-block::
0 commit comments