本人最近做一个O2O平台项目(含管理、预约、支付、接入微信等),当初出于人员能力、成本等考虑,选择了标准的MEAN作为技术选型。做起来确实很快,但随着项目需求的迭代,我感觉该技术选型特别是mongodb存在非常多的局限,主要如下:
1、mongodb不支持join的操作,只能简单通过populate扩展,因此,但凡有跨表的查询、统计都非常麻烦;我们现在很多是通过数据的冗余来做的,就是干脆数据字段在几个集合里都存。
2、mongodb不支持事务,因此很多回滚的操作我们现在是在业务的同步框架里处理,代码显得非常冗余,且本质上仍然不是真正意义上的回滚;
我听说业内现在有越来越多的纯MEAN的大项目,我不知道大家是怎么解决上述问题的?还是说核心业务逻辑仍然用的是关系型数据库。
我想大声告诉你2017-05-02 09:19:43
Some of my projects have encountered join problems. My solution is to store the corresponding ObjectIds and achieve the purpose of joining through mongodb's aggregation. I used the WiredTiger engine, so I solved the problem of locking the database during large amounts of reading and writing. Also try to avoid traditional SQL design thinking and development logic when designing the database. A collection should try to correspond to one event. Later, due to the expansion of the project, I introduced the worker development model and changed the relationship between the logical layers to workers with independent threads. At present, it has a good effect in dealing with a large number of concurrency without online connections (similar to the effect of grabbing red envelopes with no online people). Just a little humble opinion for reference only.
Also, the limitations of mongodb will be very uncomfortable for people who are used to the SQL development model. But in the era of big data, the advantages of mongodb are obvious. At present, the basic structure of my project is:
Server: nginx+mongodb+php-fpm+ubuntu
Main program: MVC (php) // Values provide logical relationship exchange
Auxiliary program: Workers // Logic corresponding to multi-thread processing Relational database interaction
巴扎黑2017-05-02 09:19:43
Didn’t you consider it when selecting technology? There is no need to only use mongo, multiple libraries can coexist
漂亮男人2017-05-02 09:19:43
Everyone, actually my question is not whether Mongo is defective or whether it should be replaced. Rather, assuming that the database is not switched, is there any solution to the above problem? I'm sure there are others in the industry who have encountered and solved these problems.
仅有的幸福2017-05-02 09:19:43
Mongodb is not suitable for this kind of project. It is suitable for query type, and it is simple. For projects with strong relationships, relational databases are still used