diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index be33a31..b7451f0 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -395,6 +395,8 @@ EOS find().count() end + alias :size :count + protected def normalize_hint_fields(hint) diff --git a/test/test_collection.rb b/test/test_collection.rb index 3fe5a69..fbc9a49 100644 --- a/test/test_collection.rb +++ b/test/test_collection.rb @@ -112,6 +112,17 @@ class TestCollection < Test::Unit::TestCase assert_equal 2, @@test.count end + # Note: #size is just an alias for #count. + def test_size + @@test.drop + + assert_equal 0, @@test.count + assert_equal @@test.size, @@test.count + @@test.save("x" => 1) + @@test.save("x" => 2) + assert_equal @@test.size, @@test.count + end + def test_find_one id = @@test.save("hello" => "world", "foo" => "bar")