Reference SQL table to the MongoDB collection in Ruby on Rails application

137 views Asked by At

In my Blog Application built on Ruby on Rails - 4.1.4, I want to implement "Archive/Unarchive" feature for redundant blogs. I am using both Postgresql and MongoDB. Users, Posts, and Comments in Postgresql and Archived posts in MongoDB. I'm referencing posts to user with user_id in posts table.

Now, In archived_posts collection in MongoDB, I want association of User table (postgresql) to the ArchivedPost collection (MongoDB). Is it possible to achieve such reference/relation?

2

There are 2 answers

0
Prashant Vithani On

After a lot of searching, I found a gem 'tenacity' which offers such service.

You can look at the documentation at https://github.com/jwood/tenacity. I recently used the same in my project and it's working fine.

0
Alexander Ushakov On

In MongoDB you may reference to the records in your Postgresql user table by their ID. But there is no any referential integrity in such solution.

If you delete user record from Postgresql, record in MongoDB will still be there with id of nonexistence user. If it is a problem for your service than you'll need some kind of synchronization between user table in Postgresql and archived post table in MongoDB