Skip to content

Commit 39ee65c

Browse files
MONGOID-5388 - Add Index wildcard_projection option and test for wildcard index (#5328)
* Add Index wildcard_projection option and test for wildcard index * Update lib/mongoid/indexable/validators/options.rb * Remove unneeded specs Co-authored-by: shields <[email protected]> Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 4f8f922 commit 39ee65c

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

lib/config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ en:
238238
\_\_language_override\n
239239
\_\_default_language\n
240240
\_\_collation\n
241+
\_\_wildcard_projection: { 'path.to.field.a': 1, 'path.to.field.b': 0 }\n
241242
Valid types are: 1, -1, '2d', '2dsphere', 'geoHaystack (deprecated)', 'text', 'hashed'\n\n
242243
Example:\n
243244
\_\_class Band\n

lib/mongoid/indexable/validators/options.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ module Options
2828
:text_version,
2929
:version,
3030
:partial_filter_expression,
31-
:collation
31+
:collation,
32+
:wildcard_projection,
3233
]
3334

3435
VALID_TYPES = [

spec/mongoid/indexable_spec.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,11 @@ def self.hereditary?
223223
let(:klass) do
224224
Class.new do
225225
include Mongoid::Document
226-
field :a, as: :authentication_token
226+
227227
store_in collection: :specs
228+
229+
field :a, as: :authentication_token
230+
field :username
228231
end
229232
end
230233

@@ -588,6 +591,25 @@ def self.hereditary?
588591
end
589592
end
590593

594+
context "when using a wildcard index" do
595+
596+
before do
597+
klass.index({ '$**': 1 }, wildcard_projection: { _id: 1, username: 0 })
598+
end
599+
600+
let(:spec) do
601+
klass.index_specification('$**': 1)
602+
end
603+
604+
it "creates the index" do
605+
expect(spec).to be_a(Mongoid::Indexable::Specification)
606+
end
607+
608+
it "sets the index with correct options" do
609+
expect(spec.options).to eq(wildcard_projection: { _id: 1, username: 0 })
610+
end
611+
end
612+
591613
context "when providing an invalid option" do
592614

593615
it "raises an error" do

0 commit comments

Comments
 (0)