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
115
115
end
116
116
command . update ( view_options )
117
117
command . update ( options . slice ( :collation ) )
118
+
118
119
# 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
+
123
126
command . merge! ( Options ::Mapper . transform_documents ( options , MAPPINGS ) )
124
127
command
125
128
end
Original file line number Diff line number Diff line change @@ -250,7 +250,20 @@ def new(options)
250
250
end
251
251
252
252
def initial_query_op ( session )
253
- Operation ::MapReduce . new ( map_reduce_spec ( session ) )
253
+ spec = map_reduce_spec ( session )
254
+ # Read preference isn't simply passed in the command payload
255
+ # (it may need to be converted to wire protocol flags).
256
+ # Passing it in command payload produces errors on at least
257
+ # 5.0 mongoses.
258
+ # In the future map_reduce_command should remove :read
259
+ # from its return value, however we cannot do this right now
260
+ # due to Mongoid 7 relying on :read being returned as part of
261
+ # the command - see RUBY-2932.
262
+ # Delete :read here for now because it cannot be sent to mongos this way.
263
+ spec = spec . dup
264
+ spec [ :selector ] = spec [ :selector ] . dup
265
+ spec [ :selector ] . delete ( :read )
266
+ Operation ::MapReduce . new ( spec )
254
267
end
255
268
256
269
def valid_server? ( server )
Original file line number Diff line number Diff line change 878
878
end
879
879
end
880
880
end
881
+
882
+ describe '#map_reduce_spec' do
883
+ context 'when read preference is given' do
884
+ let ( :view_options ) do
885
+ { read : { mode : :secondary } }
886
+ end
887
+
888
+ context 'selector' do
889
+ # For compatibility with released versions of Mongoid, this method
890
+ # must return read preference under the :read key.
891
+ it 'contains read preference' do
892
+ map_reduce_spec [ :selector ] [ :read ] . should == { 'mode' => :secondary }
893
+ end
894
+ end
895
+ end
896
+ end
881
897
end
You can’t perform that action at this time.
0 commit comments