Skip to content

Commit

Permalink
Don't include $orderby in updates.
Browse files Browse the repository at this point in the history
This causes MongoDB to simply ignore the update command.

[ fix mongoid/mongoid#2430 ]
  • Loading branch information
durran committed Oct 4, 2012
1 parent b5f6f49 commit 9d27db8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

Moped::Session.new([ "ssl.mongohq.com:10004" ], ssl: true)

## 1.2.6

### Resolved Issues

* mongoid/mongoid\#2430 Don't include $orderby criteria in update calls.

## 1.2.5

### Resolved Issues
Expand Down
2 changes: 1 addition & 1 deletion lib/moped/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def update(change, flags = nil)
session.context.update(
operation.database,
operation.collection,
operation.selector,
operation.selector["$query"] || operation.selector,
change,
flags: flags
)
Expand Down
54 changes: 44 additions & 10 deletions spec/moped/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -503,25 +503,59 @@

describe "#update" do

before do
users.insert(documents)
users.find(scope: scope).update("$set" => { "updated" => true })
context "when no sorting is provided" do

before do
users.insert(documents)
users.find(scope: scope).update("$set" => { "updated" => true })
end

it "updates the first matching document" do
users.find(scope: scope, updated: true).count.should eq 1
end
end

it "updates the first matching document" do
users.find(scope: scope, updated: true).count.should eq 1
context "when sorting is provided" do

before do
users.insert(documents)
users.find(scope: scope).
sort(updated: 1).
update("$set" => { "updated" => true })
end

it "updates the first matching document" do
users.find(scope: scope, updated: true).count.should eq 1
end
end
end

describe "#update_all" do

before do
users.insert(documents)
users.find(scope: scope).update_all("$set" => { "updated" => true })
context "when no sorting is provided" do

before do
users.insert(documents)
users.find(scope: scope).update_all("$set" => { "updated" => true })
end

it "updates all matching documents" do
users.find(scope: scope, updated: true).count.should eq 2
end
end

it "updates all matching documents" do
users.find(scope: scope, updated: true).count.should eq 2
context "when sorting is provided" do

before do
users.insert(documents)
users.find(scope: scope).
sort(updated: 1).
update_all("$set" => { "updated" => true })
end

it "updates all matching documents" do
users.find(scope: scope, updated: true).count.should eq 2
end
end
end

Expand Down

0 comments on commit 9d27db8

Please sign in to comment.