fix for count when find has fields specified
This commit is contained in:
parent
834a176dbe
commit
496af2be9c
@ -66,7 +66,8 @@ module Mongo
|
|||||||
# database error.
|
# database error.
|
||||||
def count
|
def count
|
||||||
command = OrderedHash["count", @collection.name,
|
command = OrderedHash["count", @collection.name,
|
||||||
"query", @query.selector]
|
"query", @query.selector,
|
||||||
|
"fields", @query.fields()]
|
||||||
response = @db.db_command(command)
|
response = @db.db_command(command)
|
||||||
return response['n'].to_i if response['ok'] == 1
|
return response['n'].to_i if response['ok'] == 1
|
||||||
return 0 if response['errmsg'] == "ns missing"
|
return 0 if response['errmsg'] == "ns missing"
|
||||||
|
@ -220,4 +220,14 @@ class CursorTest < Test::Unit::TestCase
|
|||||||
assert_equal(by_location,
|
assert_equal(by_location,
|
||||||
@@db.db_command("cursorInfo" => 1)["byLocation_size"])
|
@@db.db_command("cursorInfo" => 1)["byLocation_size"])
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user