Mongodb, mongoid on ruby on rails: Could not load database configuration. No such file - ["config/database.yml"]

If you're looking to have a rails app without active record (an app that doesn't use SQL), you may be surprized to find out that excluding "active_record/railtie" still does not remove active_record from the stack. So how do you remove active_record? This question is relevant when you convert or create a new rails app, that uses mongoid (mongodb) for its storage.

[AI] By taking these steps, you ensure that your Rails application seamlessly integrates with MongoDB through Mongoid, providing a robust and efficient alternative to the traditional SQL-backed setup. Remember to thoroughly test your application after making these changes to ensure its proper functionality with the desired database system.

As it turns out, other railties have implicit dependency on active_record, so you'd have to remove them as well. In config/application.rb :

## From: https://github.com/rails/spring/issues/601
# require "rails/all"
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
# require "action_mailbox/engine"
# require "action_text/engine"
require "action_view/railtie"
# require "action_cable/engine"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

I should also mention that it may or may not be a great idea to actually remove active_record, if you need all the things that depend on it. Rails is a heavy framework, and removing active_record should lighten the deployment somewhat. On the other hand, maybe the performance improvement is not worth the inconvenience of having a large portion of the framework unavailable. The developer should decide in their own use case, what are the best trade offs.

[ai] Ultimately, the decision to remove active_record from a Rails application hinges on careful consideration of the specific needs and constraints of the project. While it may lead to a reduction in deployment overhead and potentially enhance performance, it's crucial to weigh these advantages against the inconvenience of losing a significant part of the framework. Active Record provides an intuitive interface for interacting with databases, and if your application heavily relies on database-related functionalities, removing it might not be the most prudent choice. Additionally, consider the impact on maintainability, as other developers working on the project may be more accustomed to the conventional Rails setup. Therefore, before making such a decision, it's advisable to thoroughly evaluate the trade-offs and ensure that the benefits align with the specific goals and requirements of the application.

Please login or register to post a comment.