From 33f4aca658c9f67467de99646f8c1438c104c29f Mon Sep 17 00:00:00 2001 From: Houdini Date: Mon, 22 Mar 2010 06:33:37 +0300 Subject: [PATCH] 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. --- lib/mongo/cursor.rb | 2 ++ test/unit/cursor_test.rb | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index dee3a79..27896c2 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -282,6 +282,8 @@ module Mongo returning({}) do |hash| fields.each { |field| hash[field] = 1 } end + when Hash + return fields end end diff --git a/test/unit/cursor_test.rb b/test/unit/cursor_test.rb index 3be5839..178d228 100644 --- a/test/unit/cursor_test.rb +++ b/test/unit/cursor_test.rb @@ -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