I worked around this by loading constantizing each model and then
calling ensure_indexes! after the fact. Below is my entire mongo.rb
initializer (with rails 2.3.4).
# connect to mongo
MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017, {
:auto_reconnect => true,
:logger => Rails.logger
})
# setup default MM database
MongoMapper.database = "harmony-#{Rails.env}"
# make sure each model is loaded and thus indexes are collected
Dir[Rails.root + 'app/models/**/*.rb'].each do |model_path|
File.basename(model_path, '.rb').classify.constantize
end
# ensure all needed indexes are created
MongoMapper.ensure_indexes!
# handle passenger forking
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
MongoMapper.database.connect_to_master if forked
end
end
This seems to get the trick done for me and I confirmed that the
indexes were created and such. If anyone knows a better way to get
around this, please let me know as this feels insanely dirty. Thanks.
Regards,
John Nunemaker