Skip to content

Instantly share code, notes, and snippets.

@andreif
Forked from ches/db.rake
Created July 25, 2011 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreif/1103815 to your computer and use it in GitHub Desktop.
Save andreif/1103815 to your computer and use it in GitHub Desktop.
Rake task to open MongoDB console for a Rails app with Mongoid
namespace :db do
desc 'Open a MongoDB console with connection parameters for the current Rails.env'
task :console => :environment do
conn = Mongoid.master.connection
opts = ''
opts << ' --username ' << conn.username if conn.username rescue nil
opts << ' --password ' << conn.password if conn.password rescue nil
opts << ' --host ' << conn.host
opts << ' --port ' << conn.port.to_s
system "mongo #{opts} #{Mongoid.master.name}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment