2009-02-03 17:15:35 +00:00
|
|
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
|
|
require 'mongo'
|
|
|
|
|
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}"
|
2009-08-20 22:48:09 +00:00
|
|
|
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
|
|
|
|
coll.clear
|
|
|
|
|
|
|
|
# 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
|
2009-02-26 17:06:03 +00:00
|
|
|
db.create_index('test', 'a')
|
2009-02-03 17:15:35 +00:00
|
|
|
p db.index_information('test')
|
|
|
|
|
|
|
|
# Destroy the collection
|
|
|
|
coll.drop
|