File tree Expand file tree Collapse file tree 3 files changed +37
-5
lines changed
lib/mongo/collection/view
spec/mongo/collection/view Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -115,11 +115,14 @@ def map_reduce_command
115115 end
116116 command . update ( view_options )
117117 command . update ( Utils . slice_hash ( options , :collation ) )
118+
118119 # Read preference isn't simply passed in the command payload
119- # (it may need to be converted to wire protocol flags)
120- # so remove it here and hopefully it's handled elsewhere.
121- # If not, RUBY-2706.
122- command . delete ( :read )
120+ # (it may need to be converted to wire protocol flags).
121+ # Ideally it should be removed here, however due to Mongoid 7
122+ # using this method and requiring :read to be returned from it,
123+ # we cannot do this just yet - see RUBY-2932.
124+ #command.delete(:read)
125+
123126 command . merge! ( Options ::Mapper . transform_documents ( options , MAPPINGS ) )
124127 command
125128 end
Original file line number Diff line number Diff line change @@ -248,7 +248,20 @@ def new(options)
248248 end
249249
250250 def initial_query_op ( session )
251- Operation ::MapReduce . new ( map_reduce_spec ( session ) )
251+ spec = map_reduce_spec ( session )
252+ # Read preference isn't simply passed in the command payload
253+ # (it may need to be converted to wire protocol flags).
254+ # Passing it in command payload produces errors on at least
255+ # 5.0 mongoses.
256+ # In the future map_reduce_command should remove :read
257+ # from its return value, however we cannot do this right now
258+ # due to Mongoid 7 relying on :read being returned as part of
259+ # the command - see RUBY-2932.
260+ # Delete :read here for now because it cannot be sent to mongos this way.
261+ spec = spec . dup
262+ spec [ :selector ] = spec [ :selector ] . dup
263+ spec [ :selector ] . delete ( :read )
264+ Operation ::MapReduce . new ( spec )
252265 end
253266
254267 def valid_server? ( server )
Original file line number Diff line number Diff line change 865865 end
866866 end
867867 end
868+
869+ describe '#map_reduce_spec' do
870+ context 'when read preference is given' do
871+ let ( :view_options ) do
872+ { read : { mode : :secondary } }
873+ end
874+
875+ context 'selector' do
876+ # For compatibility with released versions of Mongoid, this method
877+ # must return read preference under the :read key.
878+ it 'contains read preference' do
879+ map_reduce_spec [ :selector ] [ :read ] . should == { 'mode' => :secondary }
880+ end
881+ end
882+ end
883+ end
868884end
You can’t perform that action at this time.
0 commit comments