File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -375,6 +375,21 @@ An equivalent filter could be constructed using the :query:`$regex` operator:
375
375
376
376
.. seealso:: :manual:`$regex </reference/operator/query/regex>` in the MongoDB manual
377
377
378
+ Although MongoDB's regular expression syntax is not exactly the same as PHP's
379
+ :php:`PCRE <manual/en/book.pcre.php>` syntax, :php:`preg_quote() <preg_quote>`
380
+ may be used to escape special characters that should be matched as-is. The
381
+ following example finds restaurants whose name starts with "(Library)":
382
+
383
+ .. code-block:: php
384
+
385
+ <?php
386
+
387
+ $collection = (new MongoDB\Client)->test->restaurants;
388
+
389
+ $cursor = $collection->find([
390
+ 'name' => new MongoDB\BSON\Regex('^' . preg_quote('(Library)')),
391
+ ]);
392
+
378
393
.. _php-aggregation:
379
394
380
395
Complex Queries with Aggregation
You can’t perform that action at this time.
0 commit comments