From 1146e5692a34b04a2ba4ea1810a30a162cadfa80 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Tue, 15 Nov 2011 16:24:21 -0500 Subject: [PATCH] RUBY-341 fix :max_scan and :show_disk_loc --- lib/mongo/collection.rb | 2 +- lib/mongo/cursor.rb | 7 ++++--- test/collection_test.rb | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index 8a737c1..1e4eccf 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -217,7 +217,7 @@ module Mongo max_scan = opts.delete(:max_scan) return_key = opts.delete(:return_key) transformer = opts.delete(:transformer) - show_disk_loc = opts.delete(:max_scan) + show_disk_loc = opts.delete(:show_disk_loc) read = opts.delete(:read) || @read_preference if timeout == false && !block_given? diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index 058c27d..a4c6a84 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -26,7 +26,7 @@ module Mongo attr_reader :collection, :selector, :fields, :order, :hint, :snapshot, :timeout, :full_collection_name, :transformer, - :options, :cursor_id + :options, :cursor_id, :show_disk_loc # Create a new cursor. # @@ -600,7 +600,7 @@ module Mongo spec['$hint'] = @hint if @hint && @hint.length > 0 spec['$explain'] = true if @explain spec['$snapshot'] = true if @snapshot - spec['$maxscan'] = @max_scan if @max_scan + spec['$maxScan'] = @max_scan if @max_scan spec['$returnKey'] = true if @return_key spec['$showDiskLoc'] = true if @show_disk_loc spec @@ -608,7 +608,8 @@ module Mongo # Returns true if the query contains order, explain, hint, or snapshot. def query_contains_special_fields? - @order || @explain || @hint || @snapshot + @order || @explain || @hint || @snapshot || @show_disk_loc || + @max_scan || @return_key end def close_cursor_if_query_complete diff --git a/test/collection_test.rb b/test/collection_test.rb index b34635e..cca9103 100644 --- a/test/collection_test.rb +++ b/test/collection_test.rb @@ -705,6 +705,26 @@ class TestCollection < Test::Unit::TestCase coll.ensure_index([['a', 1]]) end + + if @@version > '2.0.0' + def test_show_disk_loc + @@test.save({:a => 1}) + @@test.save({:a => 2}) + assert @@test.find({:a => 1}, :show_disk_loc => true).show_disk_loc + assert @@test.find({:a => 1}, :show_disk_loc => true).next['$diskLoc'] + @@test.remove + end + + def test_max_scan + 1000.times do |n| + @@test.save({:a => n}) + end + assert @@test.find({:a => 999}).next + assert !@@test.find({:a => 999}, :max_scan => 500).next + @@test.remove + end + end + context "Grouping" do setup do @@test.remove