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