2008-11-22 01:00:51 +00:00
|
|
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
|
|
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 14:50:48 +00:00
|
|
|
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
|
2008-12-04 22:04:06 +00:00
|
|
|
|
|
|
|
puts "Connecting to #{host}:#{port}"
|
2009-08-20 14:50:48 +00:00
|
|
|
db = Mongo::Mongo.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
|
2008-11-22 01:00:51 +00:00
|
|
|
coll.clear
|
|
|
|
|
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
|