views:

369

answers:

2

i just stumbled across a posing on the mongodb-user list where there was a discussion about passenger and forking when using mongoDB with MongoMapper.

I just wanted to remind that Rails developers need to tweak their 'environment.rb' if they use MongoDB with Passenger.

By default, Passenger spawns Ruby processes with fork(). And, as fork () shares file descriptors, the Rails app has to reopen the connection to MongoDB in the fresh new "process".

http://groups.google.com/group/mongodb-user/browse_thread/thread/f31e2d23de38136a

anyone knows if there are still issues with mongoDB and passenger or what is the best way to serve a mongoDB-rails-application with passenger?

+1  A: 

I think this "issue" is still around, but I think the fix was provided in both the thread you linked to (a link in the first message) and in a gist by John Nunemaker (http://gist.github.com/232953).

I believe the relevant bit of information is in the following block of code which you will place in an intializer:

if defined?(PhusionPassenger)
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
    # if using older than 0.6.5 of MM then you want database instead of connection
    # MongoMapper.database.connect_to_master if forked
    MongoMapper.connection.connect_to_master if forked
  end
end
samullen
thanks a lot! i am actually enjoying working with mongoDB a lot. i am actually thinking of using it in production as well.
z3cko
A: 

samullen is correct. As long as you include the snipped posted above, you shouldn't have any issues.

Kyle Banker
thanks for the help!
z3cko