mongo-ruby-driver/examples/admin.rb

42 lines
922 B
Ruby
Raw Permalink Normal View History

2009-02-03 17:15:35 +00:00
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
require 'pp'
include Mongo
2009-02-03 17:15:35 +00:00
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
2009-02-03 17:15:35 +00:00
puts "Connecting to #{host}:#{port}"
db = Connection.new(host, port).db('ruby-mongo-examples')
coll = db.create_collection('test')
2009-02-03 17:15:35 +00:00
# Erase all records from collection, if any
coll.clear
admin = db.admin
# Profiling level set/get
p admin.profiling_level
2009-02-03 17:15:35 +00:00
# Start profiling everything
admin.profiling_level = :all
2009-02-03 17:15:35 +00:00
# Read records, creating a profiling event
coll.find().to_a
2009-02-03 17:15:35 +00:00
# Stop profiling
admin.profiling_level = :off
2009-02-03 17:15:35 +00:00
# Print all profiling info
pp admin.profiling_info
# Validate returns a hash if all is well or raises an exception if there is a
# problem.
info = admin.validate_collection(coll.name)
2009-02-03 19:19:30 +00:00
puts "valid = #{info['ok']}"
puts info['result']
2009-02-03 17:15:35 +00:00
# Destroy the collection
coll.drop