cschaeffler
cschaeffler

Reputation: 453

MongoID, Heroku, MongoLab/HQ, w/o addons

I currently want to test out heroku mongoid mongolab/mongohq.

however, i don't want to work with heroku addons, instead, i want to config mongoid to directly use a mongolab/mongohq database via uri oder other settings. However, this doesn't really work out well.

Heres what i've done so far:

rails new test-mongoid --skip-active-record

Gemfile

gem 'mongoid'
gem 'haml'
gem 'sass'

rails g mongoid:config

scaffolded a test model

rails g scaffold Article title:string body:string

mongoid.yml

production:
  host: <%= ENV['MONGOID_HOST'] %>
  port: <%= ENV['MONGOID_PORT'] %>
  username: <%= ENV['MONGOID_USERNAME'] %>
  password: <%= ENV['MONGOID_PASSWORD'] %>
  database: <%= ENV['MONGOID_DATABASE'] %>

other try already did with mongoid.yml

production:
  uri: mongodb://<user>:<password>@<host>:<port>/<database>

filled in with my username password etc.

tested it locally with a mongodb, everything worked fine. pushed it to heroku, does not work.

anyone already did it this way to bypass those heroku addons and know how to handle it?

sincerely, cschaeffler

EDIT

configured my mongoid.yml like this

production:
  sessions:
    default:
      hosts:
        - <server>:<port>
      username: <username>
      password: <password>
      database: <dbname>

seems to be running... but if i try to go to the scaffolded Article index app.herokuapp.com/articles

i get

[2012-08-18 21:54:30] INFO  WEBrick 1.3.1
[2012-08-18 21:54:30] INFO  ruby 1.9.2 (2011-07-09) [x86_64-linux]
[2012-08-18 21:54:30] INFO  WEBrick::HTTPServer#start: pid=2 port=57443
State changed from starting to up
=> Booting WEBrick
=> Rails 3.2.1 application starting in production on http:// 0.0. 0.0:57443
=> Ctrl-C to shutdown server
=> Call with -d to detach
Started GET "/articles" for 79.199.52.102 at 2012-08-18 21:54:31 +0000
Processing by ArticlesController#index as HTML
Completed 500 Internal Server Error in 264ms
ActionView::Template::Error (undefined method `[]' for nil:NilClass):
11: 
10:   </tr>

14:     <td><%= article.title %></td>
15:     <td><%= article.body %></td>
13:   <tr>
Rendered articles/index.html.erb within layouts/application (208.2ms)
9:     <th></th>
12: <% for article in @articles %>
app/controllers/articles_controller.rb:7:in `index'

app/views/articles/index.html.erb:12:in    _app_views_articles_index_html_erb__1324099721200765517_18939540'

cache: [GET /articles] miss
GET safe-atoll-7856.herokuapp.com/articles dyno=web.1 queue=0 wait=0ms service=342ms status=500 bytes=643
Stopping remaining processes with SIGKILL
Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM
Process exited with status 137

Upvotes: 4

Views: 1255

Answers (2)

Leopd
Leopd

Reputation: 42777

Add

ruby '1.9.3'

to your Gemfile. From Mongoid 3 + Heroku (MongoHQ) cause Moped::Errors::OperationFailure

You might expect this to just work if you're using Ruby 1.9.3 locally, but no.

Upvotes: 2

apneadiving
apneadiving

Reputation: 115541

In your mongoid.yml:

production:
  host: your_host.mongohq.com
  port: 10078
  username:your_user_name
  password: your_pass
  database: your_db_name

So actually, what you're doing is fine, should just be the values which are invalid or in an improper format

Upvotes: 0

Related Questions