Skip to content

Instantly share code, notes, and snippets.

@ches
Created October 17, 2010 05:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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
@pehrlich
Copy link

Mongoid.master has been removed. Anyone know what replaces it?

@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