Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/mongo/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,8 @@ def aggregate(pipeline=nil, opts={})
seed = {
:cursor_id => cursor_info['id'],
:first_batch => cursor_info['firstBatch'],
:pool => pinned_pool
:pool => pinned_pool,
:ns => cursor_info['ns']
}

return Cursor.new(self, seed.merge!(opts))
Expand Down Expand Up @@ -901,7 +902,8 @@ def parallel_scan(num_cursors, opts={})
seed = {
:cursor_id => cursor_info['cursor']['id'],
:first_batch => cursor_info['cursor']['firstBatch'],
:pool => pinned_pool
:pool => pinned_pool,
:ns => cursor_info['ns']
}
Cursor.new(self, seed.merge!(opts))
end
Expand Down
15 changes: 9 additions & 6 deletions lib/mongo/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class Cursor
include Mongo::ReadPreference

attr_reader :collection, :selector, :fields,
:order, :hint, :snapshot, :timeout,
:full_collection_name, :transformer,
:order, :hint, :snapshot, :timeout, :transformer,
:options, :cursor_id, :show_disk_loc,
:comment, :compile_regex, :read, :tag_sets,
:acceptable_latency
Expand All @@ -40,6 +39,7 @@ def initialize(collection, opts={})
@cursor_id = opts.delete(:cursor_id)
@db = collection.db
@collection = collection
@ns = opts.delete(:ns)
@connection = @db.connection
@logger = @connection.logger

Expand Down Expand Up @@ -83,7 +83,6 @@ def initialize(collection, opts={})

batch_size(opts.delete(:batch_size) || 0)

@full_collection_name = "#{@collection.db.name}.#{@collection.name}"
@cache = opts.delete(:first_batch) || []
@returned = 0

Expand Down Expand Up @@ -124,6 +123,10 @@ def alive?
@cursor_id && @cursor_id != 0
end

def full_collection_name
@ns || "#{@collection.db.name}.#{@collection.name}"
end

# Get the next document specified the cursor options.
#
# @return [Hash, Nil] the next document or Nil if no documents remain.
Expand Down Expand Up @@ -484,7 +487,7 @@ def query_options_hash

# Clean output for inspect.
def inspect
"<Mongo::Cursor:0x#{object_id.to_s(16)} namespace='#{@db.name}.#{@collection.name}' " +
"<Mongo::Cursor:0x#{object_id.to_s(16)} namespace='#{full_collection_name}' " +
"@selector=#{@selector.inspect} @cursor_id=#{@cursor_id}>"
end

Expand Down Expand Up @@ -580,7 +583,7 @@ def send_get_more
message = BSON::ByteBuffer.new([0, 0, 0, 0])

# DB name.
BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@collection.name}")
BSON::BSON_RUBY.serialize_cstr(message, full_collection_name)

# Number of results to return.
if @limit > 0
Expand Down Expand Up @@ -636,7 +639,7 @@ def checkin_socket(sock)
def construct_query_message
message = BSON::ByteBuffer.new("", @connection.max_bson_size + MongoClient::COMMAND_HEADROOM)
message.put_int(@options)
BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@collection.name}")
BSON::BSON_RUBY.serialize_cstr(message, full_collection_name)
message.put_int(@skip)
@batch_size > 1 ? message.put_int(@batch_size) : message.put_int(@limit)
if query_contains_special_fields? && @bson # costs two serialize calls
Expand Down
12 changes: 10 additions & 2 deletions test/unit/cursor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,15 @@ class Mongo::Cursor
assert_equal 100, @cursor.batch_size
end

context "conected to mongos" do
context 'when an alternate namespace is specified' do

should 'use the alternate namespace' do
cursor = Cursor.new(@collection, :ns => 'other_db.other_collection')
assert_equal('other_db.other_collection', cursor.full_collection_name)
end
end

context "connected to mongos" do
setup do
@connection.stubs(:mongos?).returns(true)
@tag_sets = [{:dc => "ny"}]
Expand Down Expand Up @@ -211,7 +219,7 @@ class Mongo::Cursor
end
end

context "not conected to mongos" do
context "not connected to mongos" do
setup do
@connection.stubs(:mongos?).returns(false)
end
Expand Down