Skip to content

Instantly share code, notes, and snippets.

@ches
Created October 17, 2010 05:45
Show Gist options
  • Save ches/630581 to your computer and use it in GitHub Desktop.
Save ches/630581 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
args = []
args << "--username=#{conn.username}" if conn.username rescue nil
args << "--password=#{conn.password}" if conn.password rescue nil
args << "--host=#{conn.host}"
args << "--port=#{conn.port.to_s}"
args << Mongoid.master.name
exec 'mongo', *args
end
end
@dwbutler
Copy link

Master/slave replication was replaced with replica sets. See my fork: https://gist.github.com/dwbutler/6372435

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment