Answer the question
In order to leave comments, you need to log in
How to use mongodb and sql together?
The data model of my application fits very well into two databases sql and mongodb.
For example, it is convenient for me to store the history of completed customer payments in a relational database, while goods with their own different characteristics and properties in a non-relational one. The question is how to use them together when, for example, users are stored in sql with their unique id, and products are added to mongodb, with a link to the user id who added this product. How in that case to connect the data from different DB?
Answer the question
In order to leave comments, you need to log in
many active record frameworks support relationships between entities and some of them allow you to use different data repositories.
for example, in Yii2 it would be possible to create a product model, say Item, referring to a collection in mongo, and a purchase history model, let PurchaseHistory and specify the relationship between them. I suspect that in Laravel you can do the same. and for languages other than PHP, active record can allow this.
in general, it all depends on the support of working with two different databases by the tool that you choose, or on the availability of your free time to create your own. you can link data in two databases and no one will forbid you to do this, but I'm not sure that in your case there is a need for two subds at all and whether you are ready to shoulder all the work of maintaining data in a consistent state, which will be very difficult with such approach.
now many relational subds implement work with json, indexing values in it.
in addition, for a dynamic set of properties, you can always create a key-value table with columns, say, item_id | property | value where to store the properties.
in general, I would not say that the relational subd imposes some unsolvable restrictions in this matter.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question