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'
|
|
|
|
|
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
|
|
|
db.drop_collection('test')
|
|
|
|
|
2010-01-06 17:21:11 +00:00
|
|
|
# A capped collection has a max size and, optionally, a max number of records.
|
|
|
|
# Old records get pushed out by new ones once the size or max num records is reached.
|
2009-02-03 17:15:35 +00:00
|
|
|
coll = db.create_collection('test', :capped => true, :size => 1024, :max => 12)
|
|
|
|
|
|
|
|
100.times { |i| coll.insert('a' => i+1) }
|
|
|
|
|
|
|
|
# We will only see the last 12 records
|
|
|
|
coll.find().each { |row| p row }
|
|
|
|
|
|
|
|
coll.drop
|