Using MongoDB and MySQL in one application (cross-database?)?

Most of the approximately 25 MySQL tables I need to switch 3 to MongoDB. Some others I can switch, but I really have no need for this. Then there is a huge chain of relationships of about 15 tables. Of these, 4-5 will benefit from MongoDB, but about 6 I would rather have in MySQL (reasonable information that should be stable).

Is it a good idea to switch some tables to mongodb when they have relationships with others in MySQL? After switching, I think I will have to "join" them with mongoDB _id, is this a good design?

Or do I only need to switch 3 tables that I absolutely need and save the rest in MySQL?

Or should I just move everything to MongoDB? How safe is it? The reviews are somewhat confused - some say that MongoDB can lose some data, some say that it is safe, like any DBMS.

+6
source share
2 answers

Yes, this is a valid approach. It is not uncommon to store your normalized / transactional data in a relational database and use a NoSQL database such as MongoDB for other data types.

An example is an e-commerce website. You can select users and payment transactions in mySQL, but keep the product inventory in the MongoDB cluster.

By splitting the data through mySQL and Mongo, you will lose the ability to force referential integrity, but this is not necessarily a problem depending on your data. You can still store links to Mongo documents from mySQL; you simply cannot enforce these relationships at the database level.

I would start by moving the first three tables, then if all goes well, think about moving others. But there is nothing wrong with a hybrid approach if you want other data to remain in mySQL.

+10
source

I suggest you use the right tool for the job. MongoDB has several use cases where it really excels. MySQL is great for ensuring transaction integrity. If you don’t need the benefits of MySQL, moving just one data warehouse can make your life easier. If you need to handle transactional integrity that is impossible to work with in MongoDB, you just make your life more difficult.

+3
source

Source: https://habr.com/ru/post/896541/


All Articles