2010-01-06 17:21:11 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
|
2012-03-30 20:56:51 +00:00
|
|
|
require 'rubygems'
|
2008-11-22 01:00:51 +00:00
|
|
|
require 'mongo'
|
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
include Mongo
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2008-12-29 22:11:44 +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
|
2008-12-04 22:04:06 +00:00
|
|
|
|
|
|
|
puts "Connecting to #{host}:#{port}"
|
2009-08-20 22:48:09 +00:00
|
|
|
db = Connection.new(host, port).db('ruby-mongo-examples')
|
2008-11-22 01:00:51 +00:00
|
|
|
coll = db.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
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2009-02-03 17:15:35 +00:00
|
|
|
# Insert 3 records
|
2008-12-17 16:43:00 +00:00
|
|
|
3.times { |i| coll.insert({'a' => i+1}) }
|
2008-12-02 00:36:20 +00:00
|
|
|
|
2008-12-02 01:01:13 +00:00
|
|
|
puts "There are #{coll.count()} records in the test collection. Here they are:"
|
2008-11-22 01:00:51 +00:00
|
|
|
coll.find().each { |doc| puts doc.inspect }
|
2009-02-03 17:15:35 +00:00
|
|
|
|
|
|
|
# Destroy the collection
|
|
|
|
coll.drop
|