added Collection#stats and DB#stats

This commit is contained in:
Kyle Banker 2010-04-06 18:29:39 -04:00
parent 35dac1f31e
commit 84fb41c39f
5 changed files with 39 additions and 0 deletions

View File

@ -1,4 +1,9 @@
0.20 0.20
* Support for new commands:
* Collection#find_and_modify
* Collection#stats
* DB#stats
* Exception class adjustments: * Exception class adjustments:
* Mongo::InvalidObjectID moved to BSON::InvalidObjectID * Mongo::InvalidObjectID moved to BSON::InvalidObjectID
* Mongo::InvalidDocument moved to BSON::InvalidDocument * Mongo::InvalidDocument moved to BSON::InvalidDocument

View File

@ -608,6 +608,13 @@ module Mongo
@db.collections_info(@name).next_document['options'] @db.collections_info(@name).next_document['options']
end end
# Return stats on the collection. Uses MongoDB's collstats command.
#
# @return [Hash]
def stats
@db.command({:collstats => @name})
end
# Get the number of documents in this collection. # Get the number of documents in this collection.
# #
# @return [Integer] # @return [Integer]

View File

@ -386,6 +386,14 @@ module Mongo
info info
end end
# Return stats on this database. Uses MongoDB's dbstats command.
#
# @return [Hash]
def stats
self.command({:dbstats => 1})
end
# Create a new index on the given collection. # Create a new index on the given collection.
# Normally called by Collection#create_index. # Normally called by Collection#create_index.
# #

View File

@ -399,6 +399,15 @@ class TestCollection < Test::Unit::TestCase
end end
end end
if @@version >= "1.3.5"
def test_coll_stats
@@test << {:n => 1}
@@test.create_index("n")
assert_equal "#{MONGO_TEST_DB}.test", @@test.stats['ns']
end
end
def test_saving_dates_pre_epoch def test_saving_dates_pre_epoch
begin begin
@@test.save({'date' => Time.utc(1600)}) @@test.save({'date' => Time.utc(1600)})

View File

@ -20,6 +20,7 @@ class DBTest < Test::Unit::TestCase
@@conn = Connection.new(@@host, @@port) @@conn = Connection.new(@@host, @@port)
@@db = @@conn.db(MONGO_TEST_DB) @@db = @@conn.db(MONGO_TEST_DB)
@@users = @@db.collection('system.users') @@users = @@db.collection('system.users')
@@version = @@conn.server_version
def test_close def test_close
@@conn.close @@conn.close
@ -220,6 +221,15 @@ class DBTest < Test::Unit::TestCase
assert !@@db.remove_user("joe") assert !@@db.remove_user("joe")
end end
if @@version >= "1.3.5"
def test_db_stats
stats = @@db.stats
assert stats.has_key?('collections')
assert stats.has_key?('dataSize')
end
end
context "database profiling" do context "database profiling" do
setup do setup do
@db = @@conn[MONGO_TEST_DB] @db = @@conn[MONGO_TEST_DB]