mongo-ruby-driver/bin/mongo_console

22 lines
571 B
Ruby
Executable File

#!/usr/bin/env ruby
org_argv = ARGV.dup
ARGV.clear
require 'irb'
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include Mongo
host = org_argv[0] || ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
dbnm = org_argv[2] || ENV['MONGO_RUBY_DRIVER_DB'] || 'ruby-mongo-console'
puts "Connecting to #{host}:#{port} (CONN) on with database #{dbnm} (DB)"
CONN = Mongo::Mongo.new(host, port)
DB = CONN.db(dbnm)
puts "Starting IRB session..."
IRB.start(__FILE__)