diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index 63dcc3e..bd4bafb 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -88,6 +88,16 @@ module Mongo @hint = nil end + # Indicate whether this is a capped collection. + # + # @raise [Mongo::OperationFailure] + # if the collection doesn't exist. + # + # @return [Boolean] + def capped? + @db.command({:collstats => @name})['capped'] == 1 + end + # Return a sub-collection of this collection by name. If 'users' is a collection, then # 'users.comments' is a sub-collection of users. # diff --git a/test/collection_test.rb b/test/collection_test.rb index 84afeb9..0c96ff7 100644 --- a/test/collection_test.rb +++ b/test/collection_test.rb @@ -10,6 +10,16 @@ class TestCollection < Test::Unit::TestCase @@test.remove end + def test_capped_method + @@db.create_collection('normal') + assert !@@db['normal'].capped? + @@db.drop_collection('normal') + + @@db.create_collection('c', :capped => true) + assert @@db['c'].capped? + @@db.drop_collection('c') + end + def test_optional_pk_factory @coll_default_pk = @@db.collection('stuff') assert_equal BSON::ObjectId, @coll_default_pk.pk_factory