Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/tutorials/ruby-driver-indexing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ when creating indexes. These options mirror the options supported by the
- The number of units within which to group the location values in a geo haystack index.
* - ``:partial_filter_expression``
- A filter for a partial index.
* - ``:hidden``
- A Boolean specifying whether the index should be hidden; a hidden index
is one that exists on the collection but will not be used by the query planner.

The :commit_quorum option
-------------------------
Expand Down
3 changes: 3 additions & 0 deletions lib/mongo/index/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def drop_all
# a geo index.
# @option options [ Hash ] :partial_filter_expression Specify a filter for a partial
# index.
# @option options [ Boolean ] :hidden When :hidden is true, this index will
# exist on the collection but not be used by the query planner when
# executing operations.
# @option options [ String | Integer ] :commit_quorum Specify how many
# data-bearing members of a replica set, including the primary, must
# complete the index builds successfully before the primary marks
Expand Down
146 changes: 146 additions & 0 deletions spec/mongo/index/view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,81 @@
end
end

context 'when hidden is specified' do
let(:index) { view.get('with_hidden_1') }

context 'on server versions <= 3.2' do
# DRIVERS-1220 Server versions 3.2 and older do not perform any option
# checking on index creation. The server will allow the user to create
# the index with the hidden option, but the server does not support this
# option and will not use it.
max_server_fcv '3.2'

let!(:result) do
view.create_many({ key: { with_hidden: 1 }, hidden: true })
end

it 'returns ok' do
expect(result).to be_successful
end

it 'creates an index' do
expect(index).to_not be_nil
end
end

context 'on server versions between 3.4 and 4.2' do
max_server_fcv '4.2'
min_server_fcv '3.4'

it 'raises an exception' do
expect do
view.create_many({ key: { with_hidden: 1 }, hidden: true })
end.to raise_error(/The field 'hidden' is not valid for an index specification/)
end
end

context 'on server versions >= 4.4' do
min_server_fcv '4.4'

context 'when hidden is true' do
let!(:result) do
view.create_many({ key: { with_hidden: 1 }, hidden: true })
end

it 'returns ok' do
expect(result).to be_successful
end

it 'creates an index' do
expect(index).to_not be_nil
end

it 'applies the hidden option to the index' do
expect(index['hidden']).to be true
end
end

context 'when hidden is false' do
let!(:result) do
view.create_many({ key: { with_hidden: 1 }, hidden: false })
end

it 'returns ok' do
expect(result).to be_successful
end

it 'creates an index' do
expect(index).to_not be_nil
end

it 'does not apply the hidden option to the index' do
expect(index['hidden']).to be_nil
end
end
end
end

context 'when collation is specified' do
min_server_fcv '3.4'

Expand Down Expand Up @@ -773,6 +848,77 @@
end
end

context 'when providing hidden option' do
let(:index) { view.get('with_hidden_1') }

context 'on server versions <= 3.2' do
# DRIVERS-1220 Server versions 3.2 and older do not perform any option
# checking on index creation. The server will allow the user to create
# the index with the hidden option, but the server does not support this
# option and will not use it.
max_server_fcv '3.2'

let!(:result) do
view.create_one({ 'with_hidden' => 1 }, { hidden: true })
end

it 'returns ok' do
expect(result).to be_successful
end

it 'creates an index' do
expect(index).to_not be_nil
end
end

context 'on server versions between 3.4 and 4.2' do
max_server_fcv '4.2'
min_server_fcv '3.4'

it 'raises an exception' do
expect do
view.create_one({ 'with_hidden' => 1 }, { hidden: true })
end.to raise_error(/The field 'hidden' is not valid for an index specification/)
end
end

context 'on server versions >= 4.4' do
min_server_fcv '4.4'

context 'when hidden is true' do
let!(:result) { view.create_one({ 'with_hidden' => 1 }, { hidden: true }) }

it 'returns ok' do
expect(result).to be_successful
end

it 'creates an index' do
expect(index).to_not be_nil
end

it 'applies the hidden option to the index' do
expect(index['hidden']).to be true
end
end

context 'when hidden is false' do
let!(:result) { view.create_one({ 'with_hidden' => 1 }, { hidden: false }) }

it 'returns ok' do
expect(result).to be_successful
end

it 'creates an index' do
expect(index).to_not be_nil
end

it 'does not apply the hidden option to the index' do
expect(index['hidden']).to be_nil
end
end
end
end

context 'when providing commit_quorum option' do
require_topology :replica_set, :sharded
context 'on server versions >= 4.4' do
Expand Down