Skip to content

Commit 7d19420

Browse files
authored
DOCSP-34413 mongodump Regex Syntax (#5307) (#5357)
* DOCSP-34413 mongodump Regex Syntax * update note w/ quote syntax rules * remove redundant links * split up paragraph * JM feedback
1 parent d81be4f commit 7d19420

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

source/reference/operator/query/regex.txt

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,29 @@ Compatibility
4141
Syntax
4242
------
4343

44-
To use :query:`$regex`, use one of the following syntaxes:
44+
To use ``$regex``, use one of the following syntaxes:
4545

4646
.. code-block:: javascript
4747

4848
{ <field>: { $regex: /pattern/, $options: '<options>' } }
49-
{ <field>: { $regex: 'pattern', $options: '<options>' } }
49+
{ "<field>": { "$regex": "pattern", "$options": "<options>" } }
5050
{ <field>: { $regex: /pattern/<options> } }
5151

52+
.. note::
53+
54+
To use ``$regex`` with :binary:`~bin.mongodump`, you must enclose the query
55+
document in single quotes ('{ ... }') to ensure that it does not interact
56+
with your shell environment.
57+
58+
The query document must be in :ref:`Extended JSON v2
59+
<mongodb-extended-json-v2>` format (either relaxed or canonical/strict mode),
60+
which includes enclosing the field names and operators in quotes. For
61+
example:
62+
63+
.. code-block:: sh
64+
65+
mongodump -d=sample_mflix -c=movies -q='{"year": {"$regex": "20"}}'
66+
5267
In MongoDB, you can also use regular expression objects (i.e.
5368
``/pattern/``) to specify regular expressions:
5469

@@ -96,7 +111,7 @@ expression.
96111
* - ``x``
97112

98113
- "Extended" capability to ignore all white space characters in
99-
the :query:`$regex` pattern unless escaped or included in a
114+
the ``$regex`` pattern unless escaped or included in a
100115
character class.
101116

102117
Additionally, it ignores characters in-between and including
@@ -121,7 +136,7 @@ expression.
121136

122137
.. note::
123138

124-
The :query:`$regex` operator does not support the global search
139+
The ``$regex`` operator does not support the global search
125140
modifier ``g``.
126141

127142
Behavior
@@ -143,14 +158,14 @@ only use JavaScript regular expression objects (i.e. ``/pattern/``
143158

144159
{ name: { $in: [ /^acme/i, /^ack/ ] } }
145160

146-
You *cannot* use :query:`$regex` operator expressions inside an
147-
:query:`$in`.
161+
You *cannot* use ``$regex`` operator expressions inside an
162+
:query:`$in` operator.
148163

149164
Implicit ``AND`` Conditions for the Field
150165
`````````````````````````````````````````
151166

152167
To include a regular expression in a comma-separated list of query
153-
conditions for the field, use the :query:`$regex` operator. For example:
168+
conditions for the field, use the ``$regex`` operator. For example:
154169

155170
.. code-block:: javascript
156171

@@ -162,7 +177,7 @@ conditions for the field, use the :query:`$regex` operator. For example:
162177
```````````````````````
163178

164179
To use either the ``x`` option or ``s`` options, you must use the
165-
:query:`$regex` operator expression *with* the :query:`$options`
180+
``$regex`` operator expression *with* the :query:`$options`
166181
operator. For example, to specify the ``i`` and the ``s`` options, you
167182
must use :query:`$options` for both:
168183

@@ -175,7 +190,7 @@ PCRE Versus JavaScript
175190
``````````````````````
176191

177192
To use {+pcre-abbr+}-supported features in a regular expression that
178-
aren't supported in JavaScript, you must use the :query:`$regex`
193+
aren't supported in JavaScript, you must use the ``$regex``
179194
operator and specify the regular expression as a string.
180195

181196
To match case-insensitive strings:
@@ -194,7 +209,7 @@ These strings match the example regular expression:
194209
- ``"acme"``
195210
- ``"Acme"``
196211

197-
The following example uses the :query:`$regex` operator to find ``name``
212+
The following example uses the ``$regex`` operator to find ``name``
198213
field strings that match the regular expression ``"(?i)a(?-i)cme"``:
199214

200215
.. code-block:: javascript
@@ -217,7 +232,7 @@ operation on both:
217232

218233
db.inventory.find( { item: { $not: /^p.*/ } } )
219234

220-
- :query:`$regex` operator expressions
235+
- ``$regex`` operator expressions
221236

222237
For example:
223238

@@ -358,7 +373,7 @@ Without the ``m`` option, the example output is:
358373
{ _id: 104, sku: 'Abc789', description: 'SKU starts with A' }
359374
]
360375

361-
If the :query:`$regex` pattern does not contain an anchor, the pattern
376+
If the ``$regex`` pattern does not contain an anchor, the pattern
362377
matches against the string as a whole, as in the following example:
363378

364379
.. code-block:: javascript

0 commit comments

Comments
 (0)