Skip to content

Commit a872b28

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

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
@@ -45,14 +45,29 @@ Compatibility
4545
Syntax
4646
------
4747

48-
To use :query:`$regex`, use one of the following syntaxes:
48+
To use ``$regex``, use one of the following syntaxes:
4949

5050
.. code-block:: javascript
5151

5252
{ <field>: { $regex: /pattern/, $options: '<options>' } }
53-
{ <field>: { $regex: 'pattern', $options: '<options>' } }
53+
{ "<field>": { "$regex": "pattern", "$options": "<options>" } }
5454
{ <field>: { $regex: /pattern/<options> } }
5555

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

@@ -100,7 +115,7 @@ expression.
100115
* - ``x``
101116

102117
- "Extended" capability to ignore all white space characters in
103-
the :query:`$regex` pattern unless escaped or included in a
118+
the ``$regex`` pattern unless escaped or included in a
104119
character class.
105120

106121
Additionally, it ignores characters in-between and including
@@ -125,7 +140,7 @@ expression.
125140

126141
.. note::
127142

128-
The :query:`$regex` operator does not support the global search
143+
The ``$regex`` operator does not support the global search
129144
modifier ``g``.
130145

131146
Behavior
@@ -147,14 +162,14 @@ only use JavaScript regular expression objects (i.e. ``/pattern/``
147162

148163
{ name: { $in: [ /^acme/i, /^ack/ ] } }
149164

150-
You *cannot* use :query:`$regex` operator expressions inside an
151-
:query:`$in`.
165+
You *cannot* use ``$regex`` operator expressions inside an
166+
:query:`$in` operator.
152167

153168
Implicit ``AND`` Conditions for the Field
154169
`````````````````````````````````````````
155170

156171
To include a regular expression in a comma-separated list of query
157-
conditions for the field, use the :query:`$regex` operator. For example:
172+
conditions for the field, use the ``$regex`` operator. For example:
158173

159174
.. code-block:: javascript
160175

@@ -166,7 +181,7 @@ conditions for the field, use the :query:`$regex` operator. For example:
166181
```````````````````````
167182

168183
To use either the ``x`` option or ``s`` options, you must use the
169-
:query:`$regex` operator expression *with* the :query:`$options`
184+
``$regex`` operator expression *with* the :query:`$options`
170185
operator. For example, to specify the ``i`` and the ``s`` options, you
171186
must use :query:`$options` for both:
172187

@@ -179,7 +194,7 @@ PCRE Versus JavaScript
179194
``````````````````````
180195

181196
To use {+pcre-abbr+}-supported features in a regular expression that
182-
aren't supported in JavaScript, you must use the :query:`$regex`
197+
aren't supported in JavaScript, you must use the ``$regex``
183198
operator and specify the regular expression as a string.
184199

185200
To match case-insensitive strings:
@@ -198,7 +213,7 @@ These strings match the example regular expression:
198213
- ``"acme"``
199214
- ``"Acme"``
200215

201-
The following example uses the :query:`$regex` operator to find ``name``
216+
The following example uses the ``$regex`` operator to find ``name``
202217
field strings that match the regular expression ``"(?i)a(?-i)cme"``:
203218

204219
.. code-block:: javascript
@@ -221,7 +236,7 @@ operation on both:
221236

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

224-
- :query:`$regex` operator expressions
239+
- ``$regex`` operator expressions
225240

226241
For example:
227242

@@ -362,7 +377,7 @@ Without the ``m`` option, the example output is:
362377
{ _id: 104, sku: 'Abc789', description: 'SKU starts with A' }
363378
]
364379

365-
If the :query:`$regex` pattern does not contain an anchor, the pattern
380+
If the ``$regex`` pattern does not contain an anchor, the pattern
366381
matches against the string as a whole, as in the following example:
367382

368383
.. code-block:: javascript

0 commit comments

Comments
 (0)