count() is 0 for non-existant collections, not an error

This commit is contained in:
Mike Dirolf 2009-06-18 09:38:55 -04:00
parent 7b0da3cb7e
commit c6536f0d27
2 changed files with 6 additions and 0 deletions

View File

@ -390,6 +390,7 @@ module XGen
oh[:query] = selector || {}
doc = db_command(oh)
return doc['n'].to_i if ok?(doc)
return 0 if doc['errmsg'] == "ns missing"
raise "Error with count command: #{doc.inspect}"
end

View File

@ -56,6 +56,11 @@ class DBAPITest < Test::Unit::TestCase
assert docs.detect { |row| row['b'] == 3 }
end
def test_count_on_nonexisting
@@db.drop_collection('foo')
assert_equal 0, @@db.collection('foo').count()
end
def test_find_simple
@r2 = @@coll.insert('a' => 2)
@r3 = @@coll.insert('b' => 3)