I am considering using MongoDB (mongo-mapper) for a portion of my rails application. I am not ready to go whole hog MongoDB because there are too many useful gems that depend on a traditional DB.
That being said there are parts of my application that would be great to leverage a document database.
Has anyone had success mixing the two approaches? How do you link activerecord models with mongomapper models?
Mongoid 7.0. 5 or higher is required to use Rails 6.0. This generator will create the config/mongoid. yml configuration file, which is used to configure the connection to the MongoDB deployment.
The answer is yes: it makes a lot of sense. Nevertheless, Rails wasn't originally built to use a document database so you must use a separate gem in place of Active Record. MongoMapper and Mongoid are the two leading gems that make it possible use MongoDB as a datastore with Rails.
The sharding and aggregation framework, coupled with document validations, fine-grained locking, a mature ecosystem of tools and a vibrant community of users are some of the key reasons why MongoDB is the go-to database for many.
“MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need.” In this article, I am going to show you how to setup schema-less database MongoDB with your Rails 5 application. I am using Ubuntu 14.04, Ruby 2.5. 1 and Rails 5.2 for this tutorial.
MongoMapper doesn't implement ActiveModel yet, but I think there are a few forks on github that do. You could use Mongoid instead (which does) and your relationships between Mongoid docs and ActiveRecord entries would just magically work. I know a number of people are doing that.
That said, I wouldn't want to mix them unless I absolutely had to have an RDBMS for some reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With