Skip to content

Commit 86c50a0

Browse files
committed
Removed deprecated options and methods.
1 parent a14d02e commit 86c50a0

File tree

5 files changed

+14
-62
lines changed

5 files changed

+14
-62
lines changed

lib/mongo/cursor.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Cursor
2121
include Mongo::Conversions
2222
include Enumerable
2323

24-
attr_reader :collection, :selector, :admin, :fields,
24+
attr_reader :collection, :selector, :fields,
2525
:order, :hint, :snapshot, :timeout,
2626
:full_collection_name, :batch_size
2727

@@ -40,10 +40,6 @@ def initialize(collection, options={})
4040

4141
@selector = convert_selector_for_query(options[:selector])
4242
@fields = convert_fields_for_query(options[:fields])
43-
if options[:admin]
44-
warn "The admin option to Cursor#new has been deprecated. The cursor should now be passed the admin collection explicitly."
45-
end
46-
@admin = options[:admin] || false
4743
@skip = options[:skip] || 0
4844
@limit = options[:limit] || 0
4945
@order = options[:order]
@@ -332,8 +328,7 @@ def refill_via_get_more
332328
message = BSON::ByteBuffer.new([0, 0, 0, 0])
333329

334330
# DB name.
335-
db_name = @admin ? 'admin' : @db.name
336-
BSON::BSON_RUBY.serialize_cstr(message, "#{db_name}.#{@collection.name}")
331+
BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@collection.name}")
337332

338333
# Number of results to return.
339334
message.put_int(@batch_size)
@@ -363,8 +358,7 @@ def send_initial_query
363358
def construct_query_message
364359
message = BSON::ByteBuffer.new
365360
message.put_int(query_opts)
366-
db_name = @admin ? 'admin' : @db.name
367-
BSON::BSON_RUBY.serialize_cstr(message, "#{db_name}.#{@collection.name}")
361+
BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@collection.name}")
368362
message.put_int(@skip)
369363
message.put_int(@limit)
370364
spec = query_contains_special_fields? ? construct_query_spec : @selector
@@ -374,7 +368,7 @@ def construct_query_message
374368
end
375369

376370
def query_log_message
377-
"#{@admin ? 'admin' : @db.name}['#{@collection.name}'].find(#{@selector.inspect}, #{@fields ? @fields.inspect : '{}'})" +
371+
"#{@db.name}['#{@collection.name}'].find(#{@selector.inspect}, #{@fields ? @fields.inspect : '{}'})" +
378372
"#{@skip != 0 ? ('.skip(' + @skip.to_s + ')') : ''}#{@limit != 0 ? ('.limit(' + @limit.to_s + ')') : ''}" +
379373
"#{@order ? ('.sort(' + @order.inspect + ')') : ''}"
380374
end

lib/mongo/db.rb

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,6 @@ def reset_error_history
335335
command(:reseterror => 1)
336336
end
337337

338-
# @deprecated please use Collection#find to create queries.
339-
#
340-
# Returns a Cursor over the query results.
341-
#
342-
# Note that the query gets sent lazily; the cursor calls
343-
# Connection#send_message when needed. If the caller never requests an
344-
# object from the cursor, the query never gets sent.
345-
def query(collection, query, admin=false)
346-
Cursor.new(self, collection, query, admin)
347-
end
348-
349338
# Dereference a DBRef, returning the document it points to.
350339
#
351340
# @param [Mongo::DBRef] dbref
@@ -406,7 +395,7 @@ def drop_index(collection_name, index_name)
406395
oh = BSON::OrderedHash.new
407396
oh[:deleteIndexes] = collection_name
408397
oh[:index] = index_name
409-
doc = command(oh)
398+
doc = command(oh, :check_response => false)
410399
ok?(doc) || raise(MongoDBError, "Error with drop_index command: #{doc.inspect}")
411400
end
412401

@@ -434,23 +423,6 @@ def stats
434423
self.command({:dbstats => 1})
435424
end
436425

437-
# Create a new index on the given collection.
438-
# Normally called by Collection#create_index.
439-
#
440-
# @param [String] collection_name
441-
# @param [String, Array] field_or_spec either either a single field name
442-
# or an array of [field name, direction] pairs. Directions should be specified as
443-
# Mongo::ASCENDING or Mongo::DESCENDING.
444-
# @param [Boolean] unique if +true+, the created index will enforce a uniqueness constraint.
445-
#
446-
# @return [String] the name of the index created.
447-
#
448-
# @deprecated
449-
def create_index(collection_name, field_or_spec, unique=false)
450-
warn "DB#create_index is now deprecated. Please use Collection#create_index instead."
451-
self.collection(collection_name).create_index(field_or_spec, :unique => unique)
452-
end
453-
454426
# Return +true+ if the supplied +doc+ contains an 'ok' field with the value 1.
455427
#
456428
# @param [Hash] doc
@@ -484,21 +456,14 @@ def ok?(doc)
484456
#
485457
# @core commands command_instance-method
486458
def command(selector, opts={}, old_check_response=false, old_sock=nil)
487-
if opts.is_a?(Hash)
488-
check_response = opts[:check_response].nil? ? true : opts[:check_response]
489-
sock = opts[:sock]
490-
else
491-
warn "The options passed to DB#command should now be passed as hash keys; the admin option has been deprecated."
492-
admin = opts
493-
check_response = old_check_response
494-
sock = old_sock
495-
end
459+
check_response = opts[:check_response].nil? ? true : opts[:check_response]
460+
sock = opts[:sock]
496461
raise MongoArgumentError, "command must be given a selector" unless selector.is_a?(Hash) && !selector.empty?
497462
if selector.keys.length > 1 && RUBY_VERSION < '1.9' && selector.class != BSON::OrderedHash
498463
raise MongoArgumentError, "DB#command requires an OrderedHash when hash contains multiple keys"
499464
end
500465

501-
result = Cursor.new(system_command_collection, :admin => admin,
466+
result = Cursor.new(system_command_collection,
502467
:limit => -1, :selector => selector, :socket => sock).next_document
503468

504469
if result.nil? || (check_response && !ok?(result))

test/db_api_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def test_index_information
289289
def test_index_create_with_symbol
290290
assert_equal @@coll.index_information.length, 1
291291

292-
name = @@db.create_index(@@coll.name, :a)
292+
name = @@coll.create_index([['a', 1]])
293293
info = @@db.index_information(@@coll.name)
294294
assert_equal name, "a_1"
295295
assert_equal @@coll.index_information, info

test/unit/cursor_test.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ class CursorTest < Test::Unit::TestCase
99
@cursor = Cursor.new(@collection)
1010
end
1111

12-
should "set admin to false" do
13-
assert_equal false, @cursor.admin
14-
15-
@cursor = Cursor.new(@collection, :admin => true)
16-
assert_equal true, @cursor.admin
17-
end
18-
1912
should "set selector" do
2013
assert @cursor.selector == {}
2114

test/unit/db_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ def insert_message(db, documents)
3131

3232
should "raise an error if the selector is omitted" do
3333
assert_raise MongoArgumentError do
34-
@db.command({}, true)
34+
@db.command({}, :check_response => true)
3535
end
3636
end
3737

3838
should "create the proper cursor" do
3939
@cursor = mock(:next_document => {"ok" => 1})
40-
Cursor.expects(:new).with(@collection, :admin => true,
40+
Cursor.expects(:new).with(@collection,
4141
:limit => -1, :selector => {:buildinfo => 1}, :socket => nil).returns(@cursor)
4242
command = {:buildinfo => 1}
43-
@db.command(command, true)
43+
@db.command(command, :check_response => true)
4444
end
4545

4646
should "raise an error when the command fails" do
4747
@cursor = mock(:next_document => {"ok" => 0})
48-
Cursor.expects(:new).with(@collection, :admin => true,
48+
Cursor.expects(:new).with(@collection,
4949
:limit => -1, :selector => {:buildinfo => 1}, :socket => nil).returns(@cursor)
5050
assert_raise OperationFailure do
5151
command = {:buildinfo => 1}
52-
@db.command(command, true, true)
52+
@db.command(command, :check_response => true)
5353
end
5454
end
5555

0 commit comments

Comments
 (0)