@@ -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
0 commit comments