Removed deprecated options and methods.
This commit is contained in:
parent
a14d02e98d
commit
86c50a0555
|
@ -21,7 +21,7 @@ module Mongo
|
||||||
include Mongo::Conversions
|
include Mongo::Conversions
|
||||||
include Enumerable
|
include Enumerable
|
||||||
|
|
||||||
attr_reader :collection, :selector, :admin, :fields,
|
attr_reader :collection, :selector, :fields,
|
||||||
:order, :hint, :snapshot, :timeout,
|
:order, :hint, :snapshot, :timeout,
|
||||||
:full_collection_name, :batch_size
|
:full_collection_name, :batch_size
|
||||||
|
|
||||||
|
@ -40,10 +40,6 @@ module Mongo
|
||||||
|
|
||||||
@selector = convert_selector_for_query(options[:selector])
|
@selector = convert_selector_for_query(options[:selector])
|
||||||
@fields = convert_fields_for_query(options[:fields])
|
@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
|
@skip = options[:skip] || 0
|
||||||
@limit = options[:limit] || 0
|
@limit = options[:limit] || 0
|
||||||
@order = options[:order]
|
@order = options[:order]
|
||||||
|
@ -332,8 +328,7 @@ module Mongo
|
||||||
message = BSON::ByteBuffer.new([0, 0, 0, 0])
|
message = BSON::ByteBuffer.new([0, 0, 0, 0])
|
||||||
|
|
||||||
# DB name.
|
# 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.
|
# Number of results to return.
|
||||||
message.put_int(@batch_size)
|
message.put_int(@batch_size)
|
||||||
|
@ -363,8 +358,7 @@ module Mongo
|
||||||
def construct_query_message
|
def construct_query_message
|
||||||
message = BSON::ByteBuffer.new
|
message = BSON::ByteBuffer.new
|
||||||
message.put_int(query_opts)
|
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(@skip)
|
||||||
message.put_int(@limit)
|
message.put_int(@limit)
|
||||||
spec = query_contains_special_fields? ? construct_query_spec : @selector
|
spec = query_contains_special_fields? ? construct_query_spec : @selector
|
||||||
|
@ -374,7 +368,7 @@ module Mongo
|
||||||
end
|
end
|
||||||
|
|
||||||
def query_log_message
|
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 + ')') : ''}" +
|
"#{@skip != 0 ? ('.skip(' + @skip.to_s + ')') : ''}#{@limit != 0 ? ('.limit(' + @limit.to_s + ')') : ''}" +
|
||||||
"#{@order ? ('.sort(' + @order.inspect + ')') : ''}"
|
"#{@order ? ('.sort(' + @order.inspect + ')') : ''}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -335,17 +335,6 @@ module Mongo
|
||||||
command(:reseterror => 1)
|
command(:reseterror => 1)
|
||||||
end
|
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.
|
# Dereference a DBRef, returning the document it points to.
|
||||||
#
|
#
|
||||||
# @param [Mongo::DBRef] dbref
|
# @param [Mongo::DBRef] dbref
|
||||||
|
@ -406,7 +395,7 @@ module Mongo
|
||||||
oh = BSON::OrderedHash.new
|
oh = BSON::OrderedHash.new
|
||||||
oh[:deleteIndexes] = collection_name
|
oh[:deleteIndexes] = collection_name
|
||||||
oh[:index] = index_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}")
|
ok?(doc) || raise(MongoDBError, "Error with drop_index command: #{doc.inspect}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -434,23 +423,6 @@ module Mongo
|
||||||
self.command({:dbstats => 1})
|
self.command({:dbstats => 1})
|
||||||
end
|
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.
|
# Return +true+ if the supplied +doc+ contains an 'ok' field with the value 1.
|
||||||
#
|
#
|
||||||
# @param [Hash] doc
|
# @param [Hash] doc
|
||||||
|
@ -484,21 +456,14 @@ module Mongo
|
||||||
#
|
#
|
||||||
# @core commands command_instance-method
|
# @core commands command_instance-method
|
||||||
def command(selector, opts={}, old_check_response=false, old_sock=nil)
|
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]
|
check_response = opts[:check_response].nil? ? true : opts[:check_response]
|
||||||
sock = opts[:sock]
|
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
|
|
||||||
raise MongoArgumentError, "command must be given a selector" unless selector.is_a?(Hash) && !selector.empty?
|
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
|
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"
|
raise MongoArgumentError, "DB#command requires an OrderedHash when hash contains multiple keys"
|
||||||
end
|
end
|
||||||
|
|
||||||
result = Cursor.new(system_command_collection, :admin => admin,
|
result = Cursor.new(system_command_collection,
|
||||||
:limit => -1, :selector => selector, :socket => sock).next_document
|
:limit => -1, :selector => selector, :socket => sock).next_document
|
||||||
|
|
||||||
if result.nil? || (check_response && !ok?(result))
|
if result.nil? || (check_response && !ok?(result))
|
||||||
|
|
|
@ -289,7 +289,7 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
def test_index_create_with_symbol
|
def test_index_create_with_symbol
|
||||||
assert_equal @@coll.index_information.length, 1
|
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)
|
info = @@db.index_information(@@coll.name)
|
||||||
assert_equal name, "a_1"
|
assert_equal name, "a_1"
|
||||||
assert_equal @@coll.index_information, info
|
assert_equal @@coll.index_information, info
|
||||||
|
|
|
@ -9,13 +9,6 @@ class CursorTest < Test::Unit::TestCase
|
||||||
@cursor = Cursor.new(@collection)
|
@cursor = Cursor.new(@collection)
|
||||||
end
|
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
|
should "set selector" do
|
||||||
assert @cursor.selector == {}
|
assert @cursor.selector == {}
|
||||||
|
|
||||||
|
|
|
@ -31,25 +31,25 @@ class DBTest < Test::Unit::TestCase
|
||||||
|
|
||||||
should "raise an error if the selector is omitted" do
|
should "raise an error if the selector is omitted" do
|
||||||
assert_raise MongoArgumentError do
|
assert_raise MongoArgumentError do
|
||||||
@db.command({}, true)
|
@db.command({}, :check_response => true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create the proper cursor" do
|
should "create the proper cursor" do
|
||||||
@cursor = mock(:next_document => {"ok" => 1})
|
@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)
|
:limit => -1, :selector => {:buildinfo => 1}, :socket => nil).returns(@cursor)
|
||||||
command = {:buildinfo => 1}
|
command = {:buildinfo => 1}
|
||||||
@db.command(command, true)
|
@db.command(command, :check_response => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "raise an error when the command fails" do
|
should "raise an error when the command fails" do
|
||||||
@cursor = mock(:next_document => {"ok" => 0})
|
@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)
|
:limit => -1, :selector => {:buildinfo => 1}, :socket => nil).returns(@cursor)
|
||||||
assert_raise OperationFailure do
|
assert_raise OperationFailure do
|
||||||
command = {:buildinfo => 1}
|
command = {:buildinfo => 1}
|
||||||
@db.command(command, true, true)
|
@db.command(command, :check_response => true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue