More flexible :fields option, supporting {}

This allows exact definition of the fields you want included in the query results. For example :fields => {:name => 1, :people => 0} will include the name key but exclude the people key.
This commit is contained in:
Houdini 2010-03-22 06:33:37 +03:00 committed by Jacques Crocker
parent a94a870202
commit 33f4aca658
2 changed files with 9 additions and 0 deletions

View File

@ -282,6 +282,8 @@ module Mongo
returning({}) do |hash|
fields.each { |field| hash[field] = 1 }
end
when Hash
return fields
end
end

View File

@ -30,6 +30,13 @@ class CursorTest < Test::Unit::TestCase
assert @cursor.fields == {:name => 1, :date => 1}
end
should "set mix fields 0 and 1" do
assert_nil @cursor.fields
@cursor = Cursor.new(@collection, :fields => {:name => 1, :date => 0})
assert @cursor.fields == {:name => 1, :date => 0}
end
should "set limit" do
assert_equal 0, @cursor.limit