Sha256: a2ca0a9fd5b1ec63abb67a73571ac4bfb0f4bd61d7dedf79a2abf9d27cfb59f0

Contents?: true

Size: 710 Bytes

Versions: 12

Compression:

Stored size: 710 Bytes

Contents

$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'

include Mongo

host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT

puts "Connecting to #{host}:#{port}"
db = Connection.new(host, port).db('ruby-mongo-examples')
db.drop_collection('test')

# 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.
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

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
mongodb-mongo-0.13 examples/capped.rb
mongodb-mongo-0.14.1 examples/capped.rb
mongodb-mongo-0.14 examples/capped.rb
pahagon-mongo-abd-0.14.1 examples/capped.rb
mongo-0.18.2 examples/capped.rb
mongo-0.18.1 examples/capped.rb
mongo-0.18 examples/capped.rb
mongo-0.17.1 examples/capped.rb
mongo-0.17 examples/capped.rb
mongo-0.16 examples/capped.rb
mongo-0.15.1 examples/capped.rb
mongo-0.15 examples/capped.rb