Skip to content

Commit 1c5e498

Browse files
MONGOID-5314: Support aliases on index options partial_filter_expression, weights, and wildcard_projection (#5267)
Co-authored-by: shields <shields@tablecheck.com>
1 parent eb788c6 commit 1c5e498

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

source/reference/indexes.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,25 @@ Indexes can be scoped to a specific database:
8282
index({ ssn: 1 }, { database: "users", unique: true, background: true })
8383
end
8484

85+
You may use aliased field names in index definitions. Field aliases
86+
will also be resolved on the following options: ``partial_filter_expression``,
87+
``weights``, ``wildcard_projection``.
88+
89+
.. code-block:: ruby
90+
91+
class Person
92+
include Mongoid::Document
93+
field :a, as: :age
94+
index({ age: 1 }, { partial_filter_expression: { age: { '$gte' => 20 } })
95+
end
96+
97+
.. note::
98+
99+
The expansion of field name aliases in index options such as
100+
``partial_filter_expression`` is performed according to the behavior of MongoDB
101+
server 6.0. Future server versions may change how they interpret these options,
102+
and Mongoid's functionality may not support such changes.
103+
85104
Mongoid can define indexes on "foreign key" fields for associations.
86105
This only works on the association macro that the foreign key is stored on:
87106

source/release-notes/mongoid-9.0.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,29 @@ defaults to ``true``.
241241
When set to false, the older, inconsistent behavior is restored.
242242

243243

244+
Support Field Aliases on Index Options
245+
--------------------------------------
246+
247+
Support has been added to use aliased field names in the following options
248+
of the ``index`` macro: ``partial_filter_expression``, ``weights``,
249+
``wildcard_projection``.
250+
251+
.. code-block:: ruby
252+
253+
class Person
254+
include Mongoid::Document
255+
field :a, as: :age
256+
index({ age: 1 }, { partial_filter_expression: { age: { '$gte' => 20 } })
257+
end
258+
259+
.. note::
260+
261+
The expansion of field name aliases in index options such as
262+
``partial_filter_expression`` is performed according to the behavior of MongoDB
263+
server 6.0. Future server versions may change how they interpret these options,
264+
and Mongoid's functionality may not support such changes.
265+
266+
244267
Bug Fixes and Improvements
245268
--------------------------
246269

0 commit comments

Comments
 (0)