Using MongoDB vs MySQL with lots of JSON fields?

前端 未结 3 1748
萌比男神i
萌比男神i 2021-02-01 17:53

There is a microblogging type of application. Two main basic database stores zeroed upon are: MySQL or MongoDB.

I am planning to denormalize lot of data I.e. A vote done

3条回答
  •  太阳男子
    2021-02-01 18:28

    One of the disadvantages of a mysql solution with stored json is that you will not be able to efficiently search on the json data. If you store it all in mongodb, you can create indexes and/or queries on all of your data including the json.

    Mongo's writes work very well, and really the only thing you lose vs mysql is transaction support, and thus the ability to rollback multipart saves. However, if you are able to commit your changes in atomic operations, then there isn't a data safety issue. If you are replicated, mongo provides an "eventually consistent" promise such that the slaves will eventually mirror the master.

    Mongodb doesn't provide native enforcement or cascading of certain db constructs such as foreign keys, so you have to manage those yourself (such as either through composition, which is one of mongo's strenghts), or through use of dbrefs.

    If you really need transaction support and robust 'safe' writes, yet still desire the flexibility provided by nosql, you might consider a hybrid solution. This would allow you to use mysql as your main post store, and then use mongodb as your 'schemaless' store. Here is a link to a doc discussing hybrid mongo/rdbms solutions: http://www.10gen.com/events/hybrid-applications The article is from 10gen's site, but you can find other examples simply by doing a quick google search.

    Update 5/28/2019

    The here have been a number of changes to both MySQL and Mongodb since this answer was posted, so the pros/cons between them have become even blurrier. This update doesn't really help with the original question, but I am doing it to make sure any new readers have a bit more recent information.

    MongoDB now supports transactions: https://docs.mongodb.com/manual/core/transactions/

    MySql now supports indexing and searching json fields: https://dev.mysql.com/doc/refman/5.7/en/json.html

提交回复
热议问题