From e64b7f3679132022a27efff5b8510f8546f2e0aa Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Wed, 19 Aug 2009 09:57:15 -0400 Subject: [PATCH] if fields is [] return just _id --- lib/mongo/collection.rb | 2 +- test/test_collection.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index e068dfc..d208680 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -85,7 +85,7 @@ module XGen # http://www.mongodb.org/display/DOCS/How+to+do+Snapshotting+in+the+Mongo+Database def find(selector={}, options={}) fields = options.delete(:fields) - fields = nil if fields && fields.empty? + fields = ["_id"] if fields && fields.empty? offset = options.delete(:offset) || 0 limit = options.delete(:limit) || 0 sort = options.delete(:sort) diff --git a/test/test_collection.rb b/test/test_collection.rb index 6a53167..e2cebc0 100644 --- a/test/test_collection.rb +++ b/test/test_collection.rb @@ -124,6 +124,7 @@ class TestCollection < Test::Unit::TestCase assert @@test.find_one(nil, :fields => ["hello"]).include?("hello") assert !@@test.find_one(nil, :fields => ["foo"]).include?("hello") + assert_equal ["_id"], @@test.find_one(nil, :fields => []).keys() assert_equal nil, @@test.find_one("hello" => "foo") assert_equal nil, @@test.find_one(OrderedHash["hello", "foo"])