added Collection#stats and DB#stats
This commit is contained in:
parent
35dac1f31e
commit
84fb41c39f
5
HISTORY
5
HISTORY
|
@ -1,4 +1,9 @@
|
|||
0.20
|
||||
|
||||
* Support for new commands:
|
||||
* Collection#find_and_modify
|
||||
* Collection#stats
|
||||
* DB#stats
|
||||
* Exception class adjustments:
|
||||
* Mongo::InvalidObjectID moved to BSON::InvalidObjectID
|
||||
* Mongo::InvalidDocument moved to BSON::InvalidDocument
|
||||
|
|
|
@ -608,6 +608,13 @@ module Mongo
|
|||
@db.collections_info(@name).next_document['options']
|
||||
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.
|
||||
#
|
||||
# @return [Integer]
|
||||
|
|
|
@ -386,6 +386,14 @@ module Mongo
|
|||
info
|
||||
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.
|
||||
# Normally called by Collection#create_index.
|
||||
#
|
||||
|
|
|
@ -399,6 +399,15 @@ class TestCollection < Test::Unit::TestCase
|
|||
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
|
||||
begin
|
||||
@@test.save({'date' => Time.utc(1600)})
|
||||
|
|
|
@ -20,6 +20,7 @@ class DBTest < Test::Unit::TestCase
|
|||
@@conn = Connection.new(@@host, @@port)
|
||||
@@db = @@conn.db(MONGO_TEST_DB)
|
||||
@@users = @@db.collection('system.users')
|
||||
@@version = @@conn.server_version
|
||||
|
||||
def test_close
|
||||
@@conn.close
|
||||
|
@ -220,6 +221,15 @@ class DBTest < Test::Unit::TestCase
|
|||
assert !@@db.remove_user("joe")
|
||||
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
|
||||
setup do
|
||||
@db = @@conn[MONGO_TEST_DB]
|
||||
|
|
Loading…
Reference in New Issue