Skip to content

Commit 55ebf36

Browse files
committed
minor: removed deprecation warning for new create_index api
1 parent 8ac3171 commit 55ebf36

File tree

6 files changed

+19
-22
lines changed

6 files changed

+19
-22
lines changed

lib/mongo/collection.rb

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,6 @@ def update(selector, document, options={})
333333
# Also note that it is permissible to create compound indexes that include a geospatial index as
334334
# long as the geospatial index comes first.
335335
#
336-
# @param [Boolean] unique if true, this index will enforce a uniqueness constraint. DEPRECATED. Future
337-
# versions of this driver will specify the uniqueness constraint using a hash param.
338-
#
339336
# @option opts [Boolean] :unique (false) if true, this index will enforce a uniqueness constraint.
340337
# @option opts [Boolean] :background (false) indicate that the index should be built in the background. This
341338
# feature is only available in MongoDB >= 1.3.2.
@@ -362,7 +359,7 @@ def update(selector, document, options={})
362359
#
363360
# @core indexes create_index-instance_method
364361
def create_index(spec, opts={})
365-
opts.assert_valid_keys(:min, :max, :background, :unique, :dropDups) if opts.is_a?(Hash)
362+
opts.assert_valid_keys(:min, :max, :background, :unique, :dropDups)
366363
field_spec = OrderedHash.new
367364
if spec.is_a?(String) || spec.is_a?(Symbol)
368365
field_spec[spec.to_s] = 1
@@ -381,20 +378,17 @@ def create_index(spec, opts={})
381378
end
382379

383380
name = generate_index_name(field_spec)
384-
if opts == true || opts == false
385-
warn "For Collection#create_index, the method for specifying a unique index has changed." +
386-
"Please pass :unique => true to the method instead."
387-
end
388-
sel = {
381+
382+
selector = {
389383
:name => name,
390384
:ns => "#{@db.name}.#{@name}",
391-
:key => field_spec,
392-
:unique => (opts == true ? true : false) }
393-
sel.merge!(opts) if opts.is_a?(Hash)
385+
:key => field_spec
386+
}
387+
selector.merge!(opts)
394388
begin
395-
response = insert_documents([sel], Mongo::DB::SYSTEM_INDEX_COLLECTION, false, true)
389+
response = insert_documents([selector], Mongo::DB::SYSTEM_INDEX_COLLECTION, false, true)
396390
rescue Mongo::OperationFailure
397-
raise Mongo::OperationFailure, "Failed to create index #{sel.inspect} with the following errors: #{response}"
391+
raise Mongo::OperationFailure, "Failed to create index #{selector.inspect} with the following errors: #{response}"
398392
end
399393
name
400394
end

lib/mongo/db.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,11 @@ def stats
404404
# @param [Boolean] unique if +true+, the created index will enforce a uniqueness constraint.
405405
#
406406
# @return [String] the name of the index created.
407+
#
408+
# @deprecated
407409
def create_index(collection_name, field_or_spec, unique=false)
408-
self.collection(collection_name).create_index(field_or_spec, unique)
410+
warn "DB#create_index is now deprecated. Please use Collection#create_index instead."
411+
self.collection(collection_name).create_index(field_or_spec, :unique => unique)
409412
end
410413

411414
# Return +true+ if the supplied +doc+ contains an 'ok' field with the value 1.

test/collection_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_safe_update
165165
end
166166
else
167167
def test_safe_update
168-
@@test.create_index("x", true)
168+
@@test.create_index("x", :unique => true)
169169
@@test.insert("x" => 5)
170170
@@test.insert("x" => 10)
171171

@@ -182,7 +182,7 @@ def test_safe_update
182182
end
183183

184184
def test_safe_save
185-
@@test.create_index("hello", true)
185+
@@test.create_index("hello", :unique => true)
186186

187187
@@test.save("hello" => "world")
188188
@@test.save("hello" => "world")
@@ -558,7 +558,7 @@ def test_small_limit
558558
end
559559

560560
should "create a unique index" do
561-
@collection.create_index([['a', Mongo::ASCENDING]], true)
561+
@collection.create_index([['a', Mongo::ASCENDING]], :unique => true)
562562
assert @collection.index_information['a_1']['unique'] == true
563563
end
564564

test/db_api_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def test_unique_index
338338

339339
@@db.drop_collection("blah")
340340
test = @@db.collection("blah")
341-
test.create_index("hello", unique=true)
341+
test.create_index("hello", :unique => true)
342342

343343
test.insert("hello" => "world")
344344
test.insert("hello" => "mike")
@@ -357,7 +357,7 @@ def test_index_on_subfield
357357

358358
@@db.drop_collection("blah")
359359
test = @@db.collection("blah")
360-
test.create_index("hello.a", unique=true)
360+
test.create_index("hello.a", :unique => true)
361361

362362
test.insert("hello" => {"a" => 4, "b" => 5})
363363
test.insert("hello" => {"a" => 7, "b" => 2})

test/threading/test_threading_large_pool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def set_up_safe_data
1919
@duplicate.insert("test" => "update")
2020
@unique.insert("test" => "insert")
2121
@unique.insert("test" => "update")
22-
@unique.create_index("test", true)
22+
@unique.create_index("test", :unique => true)
2323
end
2424

2525
def test_safe_update

test/threading_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def set_up_safe_data
1717
@duplicate.insert("test" => "update")
1818
@unique.insert("test" => "insert")
1919
@unique.insert("test" => "update")
20-
@unique.create_index("test", true)
20+
@unique.create_index("test", :unique => true)
2121
end
2222

2323
def test_safe_update

0 commit comments

Comments
 (0)