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:
parent
a94a870202
commit
33f4aca658
|
@ -282,6 +282,8 @@ module Mongo
|
|||
returning({}) do |hash|
|
||||
fields.each { |field| hash[field] = 1 }
|
||||
end
|
||||
when Hash
|
||||
return fields
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue