@@ -23,11 +23,13 @@ Upgrading to Mongoid 7.3
23
23
24
24
The following sections describe significant changes in Mongoid 7.3.
25
25
26
- Field Operator Stringification
27
- ------------------------------
26
+ Selector Key Stringification
27
+ ----------------------------
28
28
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:
31
33
32
34
.. code-block:: ruby
33
35
@@ -39,6 +41,14 @@ in its arguments. Mongoid 7.3 behavior:
39
41
# class: Band
40
42
# embedded: false>
41
43
44
+ Band.where(tag: {city: 1})
45
+ # =>
46
+ # #<Mongoid::Criteria
47
+ # selector: {"tag"=>{"city"=>1}}
48
+ # options: {}
49
+ # class: Band
50
+ # embedded: false>
51
+
42
52
Mongoid 7.2 behavior:
43
53
44
54
.. code-block:: ruby
@@ -51,85 +61,74 @@ Mongoid 7.2 behavior:
51
61
# class: Band
52
62
# embedded: false>
53
63
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})
61
65
# =>
62
66
# #<Mongoid::Criteria
63
- # selector: {"year "=>{:$in=>[2020] }}
67
+ # selector: {"tag "=>{:city=>1 }}
64
68
# options: {}
65
69
# class: Band
66
70
# embedded: false>
67
71
68
- It is expected that over time, all operators will stringify the keys in their
69
- arguments.
70
-
71
72
72
73
Condition Combination Using ``$eq``
73
74
-----------------------------------
74
75
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
+
78
81
Mongoid 7.3 behavior:
79
82
80
83
.. code-block:: ruby
81
84
82
- Band.and (year: 2020, :year.gt => 1960)
85
+ Band.where (year: 2020, :year.gt => 1960)
83
86
# =>
84
87
# #<Mongoid::Criteria
85
88
# selector: {"year"=>{"$eq"=>2020, "$gt"=>1960}}
86
89
# options: {}
87
90
# class: Band
88
91
# embedded: false>
89
92
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
-
98
93
Mongoid 7.2 behavior:
99
94
100
95
.. code-block:: ruby
101
96
102
- Band.and (year: 2020, :year.gt => 1960)
97
+ Band.where (year: 2020, :year.gt => 1960)
103
98
# =>
104
99
# #<Mongoid::Criteria
105
100
# selector: {"year"=>2020, "$and"=>[{"year"=>{"$gt"=>1960}}]}
106
101
# options: {}
107
102
# class: Band
108
103
# embedded: false>
109
104
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)
111
113
# =>
112
114
# #<Mongoid::Criteria
113
- # selector: {"year "=>{"$gt "=>1960}, "$and "=>[{"year "=>2020}]}
115
+ # selector: {"$and "=>[ {"$nor "=>[{"year "=>{"$eq "=>2020, "$gt"=>1960}}] }]}
114
116
# options: {}
115
117
# class: Band
116
118
# embedded: false>
117
119
118
- This combination is not yet performed for ``where`` and other query methods :
120
+ Mongoid 7.2 behavior :
119
121
120
122
.. code-block:: ruby
121
123
122
- Band.where(: year.gt => 1960, year: 2020 )
124
+ Band.not(year: 2020, : year.gt => 1960)
123
125
# =>
124
126
# #<Mongoid::Criteria
125
- # selector: {"year"=>{"$gt "=>1960 }, "$and"=>[{"year"=>2020 }]}
127
+ # selector: {"year"=>{"$ne "=>2020 }, "$and"=>[{"$nor"=>[{" year"=>{"$gt"=>1960}}] }]}
126
128
# options: {}
127
129
# class: Band
128
130
# embedded: false>
129
131
130
- Tt is expected that in the future other query methods will also favor
131
- using ``$eq`` over ``$and``.
132
-
133
132
134
133
Upgrading to Mongoid 7.2
135
134
========================
0 commit comments