mongo-ruby-driver/docs/examples/info.rb

32 lines
682 B
Ruby
Raw Permalink Normal View History

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'
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')
2009-02-03 17:15:35 +00:00
coll = db.collection('test')
# 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
# Insert 3 records
3.times { |i| coll.insert({'a' => i+1}) }
# Collection names in database
p db.collection_names
# More information about each collection
p db.collections_info
# Index information
2010-04-29 15:11:53 +00:00
coll.create_index('a')
2009-02-03 17:15:35 +00:00
p db.index_information('test')
# Destroy the collection
coll.drop