0

My project was created using PostgresSQL but we really intend to use MongoDB, what should I change in order for that to happen?

A lot of scaffolding already took place, so we are trying to savage any of the work already done...

2
  • This question is impossible to answer without knowing your exact project scope and seeing what you have already done. But if you really want to benefit from MongoDB, you likely need to start your database abstraction layer from scratch. MongoDB is not a drop-in replacement for relational databases. You will need to reconsider your whole data model. Commented Jan 28, 2016 at 18:43
  • @Philipp we actually modelled everything for Mongo, adding Document to the relevant classes and etc, but when creating the project, for example, we forgot to use --skip ActiveRecord... Commented Jan 28, 2016 at 18:54

3 Answers 3

3
  1. Remove database adapter gems from your Gemfile (mysql2, sqlite3, etc.)

  2. Change your config/application.rb

Remove require 'rails/all' line and require frameworks you want to use, for example:

require "action_controller/railtie"
require "action_view/railtie"
require "action_mailer/railtie"
require "active_job/railtie"
require "action_cable/engine"
require "sprockets/railtie"
require "rails/test_unit/railtie" 

NOTE: You should be using the require snippet from the rails/all.rb file that is current with your version of Rails without the active_record railtie. Here is a link to rails/all.rb on the Rails master branch.

  1. Delete your config/database.yml file, db/schema.rb and migrations (if any)

  2. Delete migration check in test/test_helper.rb

  3. Delete any ActiveRecord configuration from your config/environments files

Sign up to request clarification or add additional context in comments.

Comments

1

Better late than never! This should come in handy to somebody, someday!!!!

The following python-based migration framework does the job.

https://github.com/datawrangl3r/pg2mongo

Coming to the performance, the migration of each JSON object is dynamic and there shouldn't be any memory lock issues when you use the above framework.

Comments

0

The same situation I also I have to face . I am adding some additional points to above answer .

1) Create a file in initializers and put this code

Mongoid.load!(Rails.root.join("config/mongoid.yml"))

2) You have to remove from every model which are inheriting from ApplicationRecord and delete the application_record file.

3) If you have installed devise so you have to change
**From **

 require 'devise/orm/active_record'

to

require 'devise/orm/mongoid'

4) If you are using carrierwave so in gem file you have to replace

From

gem 'carrierwave', github: 'carrierwaveuploader/carrierwave' 

To

gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.