mongo-ruby-driver/examples/strict.rb

36 lines
788 B
Ruby
Raw Permalink Normal View History

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'
include Mongo
2009-02-03 17:15:35 +00:00
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
2009-02-03 17:15:35 +00:00
puts "Connecting to #{host}:#{port}"
db = Connection.new(host, port).db('ruby-mongo-examples')
2009-02-03 17:15:35 +00:00
db.drop_collection('does-not-exist')
db.create_collection('test')
db.strict = true
begin
# Can't reference collection that does not exist
db.collection('does-not-exist')
puts "error: expected exception"
rescue => ex
puts "expected exception: #{ex}"
end
begin
# Can't create collection that already exists
db.create_collection('test')
puts "error: expected exception"
rescue => ex
puts "expected exception: #{ex}"
end
db.strict = false
db.drop_collection('test')