minor: removed deprecation warning for new create_index api
This commit is contained in:
parent
8ac3171981
commit
55ebf36c1d
|
@ -333,9 +333,6 @@ module Mongo
|
||||||
# Also note that it is permissible to create compound indexes that include a geospatial index as
|
# Also note that it is permissible to create compound indexes that include a geospatial index as
|
||||||
# long as the geospatial index comes first.
|
# long as the geospatial index comes first.
|
||||||
#
|
#
|
||||||
# @param [Boolean] unique if true, this index will enforce a uniqueness constraint. DEPRECATED. Future
|
|
||||||
# versions of this driver will specify the uniqueness constraint using a hash param.
|
|
||||||
#
|
|
||||||
# @option opts [Boolean] :unique (false) if true, this index will enforce a uniqueness constraint.
|
# @option opts [Boolean] :unique (false) if true, this index will enforce a uniqueness constraint.
|
||||||
# @option opts [Boolean] :background (false) indicate that the index should be built in the background. This
|
# @option opts [Boolean] :background (false) indicate that the index should be built in the background. This
|
||||||
# feature is only available in MongoDB >= 1.3.2.
|
# feature is only available in MongoDB >= 1.3.2.
|
||||||
|
@ -362,7 +359,7 @@ module Mongo
|
||||||
#
|
#
|
||||||
# @core indexes create_index-instance_method
|
# @core indexes create_index-instance_method
|
||||||
def create_index(spec, opts={})
|
def create_index(spec, opts={})
|
||||||
opts.assert_valid_keys(:min, :max, :background, :unique, :dropDups) if opts.is_a?(Hash)
|
opts.assert_valid_keys(:min, :max, :background, :unique, :dropDups)
|
||||||
field_spec = OrderedHash.new
|
field_spec = OrderedHash.new
|
||||||
if spec.is_a?(String) || spec.is_a?(Symbol)
|
if spec.is_a?(String) || spec.is_a?(Symbol)
|
||||||
field_spec[spec.to_s] = 1
|
field_spec[spec.to_s] = 1
|
||||||
|
@ -381,20 +378,17 @@ module Mongo
|
||||||
end
|
end
|
||||||
|
|
||||||
name = generate_index_name(field_spec)
|
name = generate_index_name(field_spec)
|
||||||
if opts == true || opts == false
|
|
||||||
warn "For Collection#create_index, the method for specifying a unique index has changed." +
|
selector = {
|
||||||
"Please pass :unique => true to the method instead."
|
|
||||||
end
|
|
||||||
sel = {
|
|
||||||
:name => name,
|
:name => name,
|
||||||
:ns => "#{@db.name}.#{@name}",
|
:ns => "#{@db.name}.#{@name}",
|
||||||
:key => field_spec,
|
:key => field_spec
|
||||||
:unique => (opts == true ? true : false) }
|
}
|
||||||
sel.merge!(opts) if opts.is_a?(Hash)
|
selector.merge!(opts)
|
||||||
begin
|
begin
|
||||||
response = insert_documents([sel], Mongo::DB::SYSTEM_INDEX_COLLECTION, false, true)
|
response = insert_documents([selector], Mongo::DB::SYSTEM_INDEX_COLLECTION, false, true)
|
||||||
rescue Mongo::OperationFailure
|
rescue Mongo::OperationFailure
|
||||||
raise Mongo::OperationFailure, "Failed to create index #{sel.inspect} with the following errors: #{response}"
|
raise Mongo::OperationFailure, "Failed to create index #{selector.inspect} with the following errors: #{response}"
|
||||||
end
|
end
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
|
@ -404,8 +404,11 @@ module Mongo
|
||||||
# @param [Boolean] unique if +true+, the created index will enforce a uniqueness constraint.
|
# @param [Boolean] unique if +true+, the created index will enforce a uniqueness constraint.
|
||||||
#
|
#
|
||||||
# @return [String] the name of the index created.
|
# @return [String] the name of the index created.
|
||||||
|
#
|
||||||
|
# @deprecated
|
||||||
def create_index(collection_name, field_or_spec, unique=false)
|
def create_index(collection_name, field_or_spec, unique=false)
|
||||||
self.collection(collection_name).create_index(field_or_spec, unique)
|
warn "DB#create_index is now deprecated. Please use Collection#create_index instead."
|
||||||
|
self.collection(collection_name).create_index(field_or_spec, :unique => unique)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return +true+ if the supplied +doc+ contains an 'ok' field with the value 1.
|
# Return +true+ if the supplied +doc+ contains an 'ok' field with the value 1.
|
||||||
|
|
|
@ -165,7 +165,7 @@ class TestCollection < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
def test_safe_update
|
def test_safe_update
|
||||||
@@test.create_index("x", true)
|
@@test.create_index("x", :unique => true)
|
||||||
@@test.insert("x" => 5)
|
@@test.insert("x" => 5)
|
||||||
@@test.insert("x" => 10)
|
@@test.insert("x" => 10)
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ class TestCollection < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_safe_save
|
def test_safe_save
|
||||||
@@test.create_index("hello", true)
|
@@test.create_index("hello", :unique => true)
|
||||||
|
|
||||||
@@test.save("hello" => "world")
|
@@test.save("hello" => "world")
|
||||||
@@test.save("hello" => "world")
|
@@test.save("hello" => "world")
|
||||||
|
@ -558,7 +558,7 @@ class TestCollection < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create a unique index" do
|
should "create a unique index" do
|
||||||
@collection.create_index([['a', Mongo::ASCENDING]], true)
|
@collection.create_index([['a', Mongo::ASCENDING]], :unique => true)
|
||||||
assert @collection.index_information['a_1']['unique'] == true
|
assert @collection.index_information['a_1']['unique'] == true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -338,7 +338,7 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
|
|
||||||
@@db.drop_collection("blah")
|
@@db.drop_collection("blah")
|
||||||
test = @@db.collection("blah")
|
test = @@db.collection("blah")
|
||||||
test.create_index("hello", unique=true)
|
test.create_index("hello", :unique => true)
|
||||||
|
|
||||||
test.insert("hello" => "world")
|
test.insert("hello" => "world")
|
||||||
test.insert("hello" => "mike")
|
test.insert("hello" => "mike")
|
||||||
|
@ -357,7 +357,7 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
|
|
||||||
@@db.drop_collection("blah")
|
@@db.drop_collection("blah")
|
||||||
test = @@db.collection("blah")
|
test = @@db.collection("blah")
|
||||||
test.create_index("hello.a", unique=true)
|
test.create_index("hello.a", :unique => true)
|
||||||
|
|
||||||
test.insert("hello" => {"a" => 4, "b" => 5})
|
test.insert("hello" => {"a" => 4, "b" => 5})
|
||||||
test.insert("hello" => {"a" => 7, "b" => 2})
|
test.insert("hello" => {"a" => 7, "b" => 2})
|
||||||
|
|
|
@ -19,7 +19,7 @@ class TestThreadingLargePool < Test::Unit::TestCase
|
||||||
@duplicate.insert("test" => "update")
|
@duplicate.insert("test" => "update")
|
||||||
@unique.insert("test" => "insert")
|
@unique.insert("test" => "insert")
|
||||||
@unique.insert("test" => "update")
|
@unique.insert("test" => "update")
|
||||||
@unique.create_index("test", true)
|
@unique.create_index("test", :unique => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_safe_update
|
def test_safe_update
|
||||||
|
|
|
@ -17,7 +17,7 @@ class TestThreading < Test::Unit::TestCase
|
||||||
@duplicate.insert("test" => "update")
|
@duplicate.insert("test" => "update")
|
||||||
@unique.insert("test" => "insert")
|
@unique.insert("test" => "insert")
|
||||||
@unique.insert("test" => "update")
|
@unique.insert("test" => "update")
|
||||||
@unique.create_index("test", true)
|
@unique.create_index("test", :unique => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_safe_update
|
def test_safe_update
|
||||||
|
|
Loading…
Reference in New Issue