Skip to content

Commit

Permalink
Use strong consistency for map/reduce operations. [ fix #2241 ]
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jul 25, 2012
1 parent b80ea7a commit 7044df8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ For instructions on upgrading to newer versions, visit
* \#2242 Fix eager loading not to load all documents when calling first or
last.

* \#2241 Map/reduce operations now always use strong consistency since they
have the potential to write to collections, most of the time.

* \#2224 `Model#inc` now accepts `BigDecimal` values.

* \#2212 Ensure errors are cleared after a save with `validate: false` in all
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/contextual/map_reduce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def output_collection
# @since 3.0.0
def results
raise Errors::NoMapReduceOutput.new(command) unless command[:out]
@results ||= session.command(command)
@results ||= session.with(consistency: :strong).command(command)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/config/mongoid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test:
hosts:
- <%=ENV["MONGOID_SPEC_HOST"]%>:<%=ENV["MONGOID_SPEC_PORT"]%>
options:
consistency: :strong
consistency: :eventual
mongohq_single:
database: <%=ENV["MONGOHQ_SINGLE_NAME"]%>
username: <%=ENV["MONGOHQ_SINGLE_USER"]%>
Expand Down
2 changes: 1 addition & 1 deletion spec/mongoid/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
end

it "sets the consistency option" do
options["consistency"].should eq(:strong)
options["consistency"].should eq(:eventual)
end
end
end
Expand Down
25 changes: 20 additions & 5 deletions spec/mongoid/sessions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,28 @@
create(name: "Tool", likes: 100)
end

let(:results) do
Band.with(database: "mongoid_test_alt").
map_reduce(map, reduce).out(inline: 1)
context "when outputting in memory" do

let(:results) do
Band.with(database: "mongoid_test_alt").
map_reduce(map, reduce).out(inline: 1)
end

it "executes the map/reduce on the correct database" do
results.first["value"].should eq({ "likes" => 200 })
end
end

it "executes the map/reduce on the correct database" do
results.first["value"].should eq({ "likes" => 200 })
context "when outputting to a collection" do

let(:results) do
Band.with(database: "mongoid_test_alt").
map_reduce(map, reduce).out(replace: "bands_output")
end

it "executes the map/reduce on the correct database" do
results.first["value"].should eq({ "likes" => 200 })
end
end
end
end
Expand Down

0 comments on commit 7044df8

Please sign in to comment.