@@ -23,8 +23,7 @@ class Cursor
2323 include Mongo ::ReadPreference
2424
2525 attr_reader :collection , :selector , :fields ,
26- :order , :hint , :snapshot , :timeout ,
27- :full_collection_name , :transformer ,
26+ :order , :hint , :snapshot , :timeout , :transformer ,
2827 :options , :cursor_id , :show_disk_loc ,
2928 :comment , :compile_regex , :read , :tag_sets ,
3029 :acceptable_latency
@@ -40,6 +39,7 @@ def initialize(collection, opts={})
4039 @cursor_id = opts . delete ( :cursor_id )
4140 @db = collection . db
4241 @collection = collection
42+ @ns = opts . delete ( :ns )
4343 @connection = @db . connection
4444 @logger = @connection . logger
4545
@@ -83,7 +83,6 @@ def initialize(collection, opts={})
8383
8484 batch_size ( opts . delete ( :batch_size ) || 0 )
8585
86- @full_collection_name = "#{ @collection . db . name } .#{ @collection . name } "
8786 @cache = opts . delete ( :first_batch ) || [ ]
8887 @returned = 0
8988
@@ -124,6 +123,10 @@ def alive?
124123 @cursor_id && @cursor_id != 0
125124 end
126125
126+ def full_collection_name
127+ @ns || "#{ @collection . db . name } .#{ @collection . name } "
128+ end
129+
127130 # Get the next document specified the cursor options.
128131 #
129132 # @return [Hash, Nil] the next document or Nil if no documents remain.
@@ -484,7 +487,7 @@ def query_options_hash
484487
485488 # Clean output for inspect.
486489 def inspect
487- "<Mongo::Cursor:0x#{ object_id . to_s ( 16 ) } namespace='#{ @db . name } . #{ @collection . name } ' " +
490+ "<Mongo::Cursor:0x#{ object_id . to_s ( 16 ) } namespace='#{ full_collection_name } ' " +
488491 "@selector=#{ @selector . inspect } @cursor_id=#{ @cursor_id } >"
489492 end
490493
@@ -580,7 +583,7 @@ def send_get_more
580583 message = BSON ::ByteBuffer . new ( [ 0 , 0 , 0 , 0 ] )
581584
582585 # DB name.
583- BSON ::BSON_RUBY . serialize_cstr ( message , " #{ @db . name } . #{ @collection . name } " )
586+ BSON ::BSON_RUBY . serialize_cstr ( message , full_collection_name )
584587
585588 # Number of results to return.
586589 if @limit > 0
@@ -636,7 +639,7 @@ def checkin_socket(sock)
636639 def construct_query_message
637640 message = BSON ::ByteBuffer . new ( "" , @connection . max_bson_size + MongoClient ::COMMAND_HEADROOM )
638641 message . put_int ( @options )
639- BSON ::BSON_RUBY . serialize_cstr ( message , " #{ @db . name } . #{ @collection . name } " )
642+ BSON ::BSON_RUBY . serialize_cstr ( message , full_collection_name )
640643 message . put_int ( @skip )
641644 @batch_size > 1 ? message . put_int ( @batch_size ) : message . put_int ( @limit )
642645 if query_contains_special_fields? && @bson # costs two serialize calls
0 commit comments