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"])