diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index 5e66fb5..eea36d2 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -21,7 +21,7 @@ module Mongo include Mongo::Conversions include Enumerable - attr_reader :collection, :selector, :admin, :fields, + attr_reader :collection, :selector, :fields, :order, :hint, :snapshot, :timeout, :full_collection_name, :batch_size @@ -40,10 +40,6 @@ module Mongo @selector = convert_selector_for_query(options[:selector]) @fields = convert_fields_for_query(options[:fields]) - if options[:admin] - warn "The admin option to Cursor#new has been deprecated. The cursor should now be passed the admin collection explicitly." - end - @admin = options[:admin] || false @skip = options[:skip] || 0 @limit = options[:limit] || 0 @order = options[:order] @@ -332,8 +328,7 @@ module Mongo message = BSON::ByteBuffer.new([0, 0, 0, 0]) # DB name. - db_name = @admin ? 'admin' : @db.name - BSON::BSON_RUBY.serialize_cstr(message, "#{db_name}.#{@collection.name}") + BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@collection.name}") # Number of results to return. message.put_int(@batch_size) @@ -363,8 +358,7 @@ module Mongo def construct_query_message message = BSON::ByteBuffer.new message.put_int(query_opts) - db_name = @admin ? 'admin' : @db.name - BSON::BSON_RUBY.serialize_cstr(message, "#{db_name}.#{@collection.name}") + BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@collection.name}") message.put_int(@skip) message.put_int(@limit) spec = query_contains_special_fields? ? construct_query_spec : @selector @@ -374,7 +368,7 @@ module Mongo end def query_log_message - "#{@admin ? 'admin' : @db.name}['#{@collection.name}'].find(#{@selector.inspect}, #{@fields ? @fields.inspect : '{}'})" + + "#{@db.name}['#{@collection.name}'].find(#{@selector.inspect}, #{@fields ? @fields.inspect : '{}'})" + "#{@skip != 0 ? ('.skip(' + @skip.to_s + ')') : ''}#{@limit != 0 ? ('.limit(' + @limit.to_s + ')') : ''}" + "#{@order ? ('.sort(' + @order.inspect + ')') : ''}" end diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index 99d7fcc..dd24606 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -335,17 +335,6 @@ module Mongo command(:reseterror => 1) end - # @deprecated please use Collection#find to create queries. - # - # Returns a Cursor over the query results. - # - # Note that the query gets sent lazily; the cursor calls - # Connection#send_message when needed. If the caller never requests an - # object from the cursor, the query never gets sent. - def query(collection, query, admin=false) - Cursor.new(self, collection, query, admin) - end - # Dereference a DBRef, returning the document it points to. # # @param [Mongo::DBRef] dbref @@ -406,7 +395,7 @@ module Mongo oh = BSON::OrderedHash.new oh[:deleteIndexes] = collection_name oh[:index] = index_name - doc = command(oh) + doc = command(oh, :check_response => false) ok?(doc) || raise(MongoDBError, "Error with drop_index command: #{doc.inspect}") end @@ -434,23 +423,6 @@ module Mongo self.command({:dbstats => 1}) end - # Create a new index on the given collection. - # Normally called by Collection#create_index. - # - # @param [String] collection_name - # @param [String, Array] field_or_spec either either a single field name - # or an array of [field name, direction] pairs. Directions should be specified as - # Mongo::ASCENDING or Mongo::DESCENDING. - # @param [Boolean] unique if +true+, the created index will enforce a uniqueness constraint. - # - # @return [String] the name of the index created. - # - # @deprecated - def create_index(collection_name, field_or_spec, unique=false) - 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 - # Return +true+ if the supplied +doc+ contains an 'ok' field with the value 1. # # @param [Hash] doc @@ -484,21 +456,14 @@ module Mongo # # @core commands command_instance-method def command(selector, opts={}, old_check_response=false, old_sock=nil) - if opts.is_a?(Hash) - check_response = opts[:check_response].nil? ? true : opts[:check_response] - sock = opts[:sock] - else - warn "The options passed to DB#command should now be passed as hash keys; the admin option has been deprecated." - admin = opts - check_response = old_check_response - sock = old_sock - end + check_response = opts[:check_response].nil? ? true : opts[:check_response] + sock = opts[:sock] raise MongoArgumentError, "command must be given a selector" unless selector.is_a?(Hash) && !selector.empty? if selector.keys.length > 1 && RUBY_VERSION < '1.9' && selector.class != BSON::OrderedHash raise MongoArgumentError, "DB#command requires an OrderedHash when hash contains multiple keys" end - result = Cursor.new(system_command_collection, :admin => admin, + result = Cursor.new(system_command_collection, :limit => -1, :selector => selector, :socket => sock).next_document if result.nil? || (check_response && !ok?(result)) diff --git a/test/db_api_test.rb b/test/db_api_test.rb index 6bb2a11..de43e77 100644 --- a/test/db_api_test.rb +++ b/test/db_api_test.rb @@ -289,7 +289,7 @@ class DBAPITest < Test::Unit::TestCase def test_index_create_with_symbol assert_equal @@coll.index_information.length, 1 - name = @@db.create_index(@@coll.name, :a) + name = @@coll.create_index([['a', 1]]) info = @@db.index_information(@@coll.name) assert_equal name, "a_1" assert_equal @@coll.index_information, info diff --git a/test/unit/cursor_test.rb b/test/unit/cursor_test.rb index 178d228..6b56859 100644 --- a/test/unit/cursor_test.rb +++ b/test/unit/cursor_test.rb @@ -9,13 +9,6 @@ class CursorTest < Test::Unit::TestCase @cursor = Cursor.new(@collection) end - should "set admin to false" do - assert_equal false, @cursor.admin - - @cursor = Cursor.new(@collection, :admin => true) - assert_equal true, @cursor.admin - end - should "set selector" do assert @cursor.selector == {} diff --git a/test/unit/db_test.rb b/test/unit/db_test.rb index 5a69deb..1005b22 100644 --- a/test/unit/db_test.rb +++ b/test/unit/db_test.rb @@ -31,25 +31,25 @@ class DBTest < Test::Unit::TestCase should "raise an error if the selector is omitted" do assert_raise MongoArgumentError do - @db.command({}, true) + @db.command({}, :check_response => true) end end should "create the proper cursor" do @cursor = mock(:next_document => {"ok" => 1}) - Cursor.expects(:new).with(@collection, :admin => true, + Cursor.expects(:new).with(@collection, :limit => -1, :selector => {:buildinfo => 1}, :socket => nil).returns(@cursor) command = {:buildinfo => 1} - @db.command(command, true) + @db.command(command, :check_response => true) end should "raise an error when the command fails" do @cursor = mock(:next_document => {"ok" => 0}) - Cursor.expects(:new).with(@collection, :admin => true, + Cursor.expects(:new).with(@collection, :limit => -1, :selector => {:buildinfo => 1}, :socket => nil).returns(@cursor) assert_raise OperationFailure do command = {:buildinfo => 1} - @db.command(command, true, true) + @db.command(command, :check_response => true) end end