@@ -42,14 +42,29 @@ Compatibility
42
42
Syntax
43
43
------
44
44
45
- To use :query:` $regex`, use one of the following syntaxes:
45
+ To use `` $regex` `, use one of the following syntaxes:
46
46
47
47
.. code-block:: javascript
48
48
49
49
{ <field>: { $regex: /pattern/, $options: '<options>' } }
50
- { <field>: { $regex: ' pattern', $options: ' <options>' } }
50
+ { " <field>" : { " $regex": " pattern", " $options": " <options>" } }
51
51
{ <field>: { $regex: /pattern/<options> } }
52
52
53
+ .. note::
54
+
55
+ To use ``$regex`` with :binary:`~bin.mongodump`, you must enclose the query
56
+ document in single quotes ('{ ... }') to ensure that it does not interact
57
+ with your shell environment.
58
+
59
+ The query document must be in :ref:`Extended JSON v2
60
+ <mongodb-extended-json-v2>` format (either relaxed or canonical/strict mode),
61
+ which includes enclosing the field names and operators in quotes. For
62
+ example:
63
+
64
+ .. code-block:: sh
65
+
66
+ mongodump -d=sample_mflix -c=movies -q='{"year": {"$regex": "20"}}'
67
+
53
68
In MongoDB, you can also use regular expression objects (i.e.
54
69
``/pattern/``) to specify regular expressions:
55
70
@@ -97,7 +112,7 @@ expression.
97
112
* - ``x``
98
113
99
114
- "Extended" capability to ignore all white space characters in
100
- the :query:` $regex` pattern unless escaped or included in a
115
+ the `` $regex` ` pattern unless escaped or included in a
101
116
character class.
102
117
103
118
Additionally, it ignores characters in-between and including
@@ -122,7 +137,7 @@ expression.
122
137
123
138
.. note::
124
139
125
- The :query:` $regex` operator does not support the global search
140
+ The `` $regex` ` operator does not support the global search
126
141
modifier ``g``.
127
142
128
143
Behavior
@@ -144,14 +159,14 @@ only use JavaScript regular expression objects (i.e. ``/pattern/``
144
159
145
160
{ name: { $in: [ /^acme/i, /^ack/ ] } }
146
161
147
- You *cannot* use :query:` $regex` operator expressions inside an
148
- :query:`$in`.
162
+ You *cannot* use `` $regex` ` operator expressions inside an
163
+ :query:`$in` operator .
149
164
150
165
Implicit ``AND`` Conditions for the Field
151
166
`````````````````````````````````````````
152
167
153
168
To include a regular expression in a comma-separated list of query
154
- conditions for the field, use the :query:` $regex` operator. For example:
169
+ conditions for the field, use the `` $regex` ` operator. For example:
155
170
156
171
.. code-block:: javascript
157
172
@@ -163,7 +178,7 @@ conditions for the field, use the :query:`$regex` operator. For example:
163
178
```````````````````````
164
179
165
180
To use either the ``x`` option or ``s`` options, you must use the
166
- :query:` $regex` operator expression *with* the :query:`$options`
181
+ `` $regex` ` operator expression *with* the :query:`$options`
167
182
operator. For example, to specify the ``i`` and the ``s`` options, you
168
183
must use :query:`$options` for both:
169
184
@@ -176,7 +191,7 @@ PCRE vs JavaScript
176
191
``````````````````
177
192
178
193
To use PCRE supported features in a regular expression that aren't
179
- supported in JavaScript, you must use the :query:` $regex` operator and
194
+ supported in JavaScript, you must use the `` $regex` ` operator and
180
195
specify the regular expression as a string.
181
196
182
197
To match case-insensitive strings:
@@ -195,7 +210,7 @@ These strings match the example regular expression:
195
210
- ``"acme"``
196
211
- ``"Acme"``
197
212
198
- The following example uses the :query:` $regex` operator to find ``name``
213
+ The following example uses the `` $regex` ` operator to find ``name``
199
214
field strings that match the regular expression ``"(?i)a(?-i)cme"``:
200
215
201
216
.. code-block:: javascript
@@ -216,7 +231,7 @@ operation on both:
216
231
217
232
db.inventory.find( { item: { $not: /^p.*/ } } )
218
233
219
- - :query:` $regex` operator expressions
234
+ - `` $regex` ` operator expressions
220
235
221
236
For example:
222
237
@@ -361,7 +376,7 @@ Without the ``m`` option, the example output is:
361
376
{ _id: 104, sku: 'Abc789', description: 'SKU starts with A' }
362
377
]
363
378
364
- If the :query:` $regex` pattern does not contain an anchor, the pattern
379
+ If the `` $regex` ` pattern does not contain an anchor, the pattern
365
380
matches against the string as a whole, as in the following example:
366
381
367
382
.. code-block:: javascript
0 commit comments