@@ -23,11 +23,13 @@ Upgrading to Mongoid 7.3
2323
2424The following sections describe significant changes in Mongoid 7.3.
2525
26- Field Operator Stringification
27- ------------------------------
26+ Selector Key Stringification
27+ ----------------------------
2828
29- Minor change: the ``and`` logical operator now stringifies field operators
30- in its arguments. Mongoid 7.3 behavior:
29+ Minor change: Mongoid now converts symbol keys to string keys in the
30+ ``Criteria`` selectors. This applies to operators as well as hash literals.
31+
32+ Mongoid 7.3 behavior:
3133
3234.. code-block:: ruby
3335
@@ -39,6 +41,14 @@ in its arguments. Mongoid 7.3 behavior:
3941 # class: Band
4042 # embedded: false>
4143
44+ Band.where(tag: {city: 1})
45+ # =>
46+ # #<Mongoid::Criteria
47+ # selector: {"tag"=>{"city"=>1}}
48+ # options: {}
49+ # class: Band
50+ # embedded: false>
51+
4252Mongoid 7.2 behavior:
4353
4454.. code-block:: ruby
@@ -51,85 +61,74 @@ Mongoid 7.2 behavior:
5161 # class: Band
5262 # embedded: false>
5363
54- Note that this stringification does not yet happen for all query construction
55- paths. For example, ``where`` does not stringify operators in both Mongoid 7.3
56- and Mongoid 7.2:
57-
58- .. code-block:: ruby
59-
60- Band.where(year: {'$in': [2020]})
64+ Band.where(tag: {city: 1})
6165 # =>
6266 # #<Mongoid::Criteria
63- # selector: {"year "=>{:$in=>[2020] }}
67+ # selector: {"tag "=>{:city=>1 }}
6468 # options: {}
6569 # class: Band
6670 # embedded: false>
6771
68- It is expected that over time, all operators will stringify the keys in their
69- arguments.
70-
7172
7273Condition Combination Using ``$eq``
7374-----------------------------------
7475
75- Minor change: when using the ``and`` method on ``Criteria`` objects and
76- providing multiple conditions on the same field in the same argument to
77- ``and``, conditions may be combined using ``$eq`` instead of ``$and``.
76+ Minor change: when using the ``where``, ``and``, ``or``, and ``nor`` methods
77+ on ``Criteria`` objects and providing multiple conditions on the same field
78+ in the same argument using the symbol operator syntax, conditions may be
79+ combined using ``$eq`` instead of ``$and``.
80+
7881Mongoid 7.3 behavior:
7982
8083.. code-block:: ruby
8184
82- Band.and (year: 2020, :year.gt => 1960)
85+ Band.where (year: 2020, :year.gt => 1960)
8386 # =>
8487 # #<Mongoid::Criteria
8588 # selector: {"year"=>{"$eq"=>2020, "$gt"=>1960}}
8689 # options: {}
8790 # class: Band
8891 # embedded: false>
8992
90- Band.and(:year.gt => 1960, year: 2020)
91- # =>
92- # #<Mongoid::Criteria
93- # selector: {"year"=>{"$gt"=>1960, "$eq"=>2020}}
94- # options: {}
95- # class: Band
96- # embedded: false>
97-
9893Mongoid 7.2 behavior:
9994
10095.. code-block:: ruby
10196
102- Band.and (year: 2020, :year.gt => 1960)
97+ Band.where (year: 2020, :year.gt => 1960)
10398 # =>
10499 # #<Mongoid::Criteria
105100 # selector: {"year"=>2020, "$and"=>[{"year"=>{"$gt"=>1960}}]}
106101 # options: {}
107102 # class: Band
108103 # embedded: false>
109104
110- Band.and(:year.gt => 1960, year: 2020)
105+ When using the ``not`` method with multiple conditions provided in the same
106+ argument, the conditions are kept together and negated as a group.
107+
108+ Mongoid 7.3 behavior:
109+
110+ .. code-block:: ruby
111+
112+ Band.not(year: 2020, :year.gt => 1960)
111113 # =>
112114 # #<Mongoid::Criteria
113- # selector: {"year "=>{"$gt "=>1960}, "$and "=>[{"year "=>2020}]}
115+ # selector: {"$and "=>[ {"$nor "=>[{"year "=>{"$eq "=>2020, "$gt"=>1960}}] }]}
114116 # options: {}
115117 # class: Band
116118 # embedded: false>
117119
118- This combination is not yet performed for ``where`` and other query methods :
120+ Mongoid 7.2 behavior :
119121
120122.. code-block:: ruby
121123
122- Band.where(: year.gt => 1960, year: 2020 )
124+ Band.not(year: 2020, : year.gt => 1960)
123125 # =>
124126 # #<Mongoid::Criteria
125- # selector: {"year"=>{"$gt "=>1960 }, "$and"=>[{"year"=>2020 }]}
127+ # selector: {"year"=>{"$ne "=>2020 }, "$and"=>[{"$nor"=>[{" year"=>{"$gt"=>1960}}] }]}
126128 # options: {}
127129 # class: Band
128130 # embedded: false>
129131
130- Tt is expected that in the future other query methods will also favor
131- using ``$eq`` over ``$and``.
132-
133132
134133Upgrading to Mongoid 7.2
135134========================
0 commit comments