Skip to content

Commit df95902

Browse files
committed
RUBY-679 raise error if exhaust used with mongos
1 parent 0ff7a59 commit df95902

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/mongo/cursor.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,12 @@ def query_opts
386386
def add_option(opt)
387387
check_modifiable
388388

389-
if exhaust?(opt) && (@limit != 0)
390-
raise MongoArgumentError, "Exhaust option is incompatible with limit."
389+
if exhaust?(opt)
390+
if @limit != 0
391+
raise MongoArgumentError, "Exhaust is incompatible with limit."
392+
elsif @connection.mongos?
393+
raise MongoArgumentError, "Exhaust is incompatible with mongos."
394+
end
391395
end
392396

393397
@options |= opt

test/functional/cursor_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ def test_limit_after_exhaust_error
110110
end
111111
end
112112

113+
def test_exhaust_with_mongos
114+
@@connection.expects(:mongos?).returns(:true)
115+
c = Cursor.new(@@coll)
116+
117+
assert_raise MongoArgumentError do
118+
c.add_option(OP_QUERY_EXHAUST)
119+
end
120+
end
121+
113122
def test_inspect
114123
selector = {:a => 1}
115124
cursor = @@coll.find(selector)

0 commit comments

Comments
 (0)