fix for count when find has fields specified

This commit is contained in:
Mike Dirolf 2009-08-24 17:21:49 -04:00
parent 834a176dbe
commit 496af2be9c
2 changed files with 12 additions and 1 deletions

View File

@ -66,7 +66,8 @@ module Mongo
# database error.
def count
command = OrderedHash["count", @collection.name,
"query", @query.selector]
"query", @query.selector,
"fields", @query.fields()]
response = @db.db_command(command)
return response['n'].to_i if response['ok'] == 1
return 0 if response['errmsg'] == "ns missing"

View File

@ -220,4 +220,14 @@ class CursorTest < Test::Unit::TestCase
assert_equal(by_location,
@@db.db_command("cursorInfo" => 1)["byLocation_size"])
end
def test_count_with_fields
@@coll.clear
@@coll.save("x" => 1)
@@coll.find({}, :fields => ["a"]).each do |doc|
fail "shouldn't have any results here"
end
assert_equal(0, @@coll.find({}, :fields => ["a"]).count())
end
end