Search code examples
ruby-on-railsrakemongoid

mongoid/mongodb and rake task authorization in production/passenger


When trying to run rake db:seed on my app, I get the error:

Database command 'count' failed: {"assertion"=>"unauthorized db:app_development lock type:-1 client:127.0.0.1", "assertionCode"=>10057, "errmsg"=>"db assertion failure", "ok"=>0.0}

I get the same error with db:drop

Mmy app is connecting to the DB fine, it's just these rake taks are failing, and I'm not sure wh. I dont think seeding should need admin privileges. Maybe it's a passenger issue?


Solution

  • You need to have the username and password set in mongoid.yml for rake tasks to be able to connect to your database.

    Example:

    production:
      host: host-name
      port: 27017
      username: itsmeyo
      password: supasecret
      database: project_production
    

    You can also have them set in environment variables, but they need to be set.

    password: <%= ENV['MONGOID_PASSWORD'] %>