@@ -185,13 +185,14 @@ Mongoid 7.2 behavior:
185185 # embedded: false>
186186
187187
188- Condition Combination Using ``$eq``
189- -----------------------------------
188+ Condition Combination Using ``$eq`` / ``$regex``
189+ ------------------------------------------------
190190
191191Minor change: when using the ``where``, ``and``, ``or``, and ``nor`` methods
192192on ``Criteria`` objects and providing multiple conditions on the same field
193193in the same argument using the symbol operator syntax, conditions may be
194- combined using ``$eq`` instead of ``$and``.
194+ combined using ``$eq`` or ``$regex`` operators, as appropriate, instead of
195+ ``$and``.
195196
196197Mongoid 7.3 behavior:
197198
@@ -205,6 +206,14 @@ Mongoid 7.3 behavior:
205206 # class: Band
206207 # embedded: false>
207208
209+ Band.where(name: /A/, :name.ne => 'Astral')
210+ # =>
211+ # #<Mongoid::Criteria
212+ # selector: {"name"=>{"$regex"=>/A/, "$ne"=>"Astral"}}
213+ # options: {}
214+ # class: Band
215+ # embedded: false>
216+
208217Mongoid 7.2 behavior:
209218
210219.. code-block:: ruby
@@ -217,6 +226,17 @@ Mongoid 7.2 behavior:
217226 # class: Band
218227 # embedded: false>
219228
229+ Band.where(name: /A/, :name.ne => 'Astral')
230+ # =>
231+ # #<Mongoid::Criteria
232+ # selector: {"name"=>/A/, "$and"=>[{"name"=>{"$ne"=>"Astral"}}]}
233+ # options: {}
234+ # class: Band
235+ # embedded: false>
236+
237+ The ``$regex`` operator is used when the value is a regular expression, i.e.
238+ an instance of ``Regexp`` or ``BSON::Regexp::Raw`` classes.
239+
220240When using the ``not`` method with multiple conditions provided in the same
221241argument, the conditions are kept together and negated as a group.
222242
0 commit comments