我学习了一些关于 NodeJS/Express
、ReactJS/Redux
的 udemy 类(class),其中一些类(class)是 MERN STACK
,我'我真的很喜欢它们。但是讲师唯一没有真正解释的是 MongoDB
的选择。在参加这些类(class)之前,我总是使用 PostgreSQL
或 MariaBD
用于我所有的项目持久层。现在我只是在所有这些类(class)中使用 MongoBD
而不知道在哪种情况下它是最佳选择。所有的讲师都只是说由于数据像 json json 数组一样存储,因此很容易解析,因为它与 Javascript
自然兼容,就像任何 JSON 格式
一样。我真的很想了解使用 Mongo 的技术原因而不是 关系数据库
或不根据任何给定的项目要求而不是仅仅因为讲师这样做而使用它
最佳答案
我曾使用过 SQL 和 MongoDB。
MongoDB
From my experience MongoDB is best suitable when you follow agile methodologies
wherein you don't really know what your JSON object will have to contain.
SQL
SQL will be best suitable where JSON object is not going to be changed, like
for bank projects, where you know the exact format of JSON which is never going
to be changed.
差异
Why I am saying this is, whenever we need to add some extra fields or need to
link some fields with primary, foreign keys it would be pain and wouldn't know
what could go wrong.
Wherein in MongoDB if you need to reference some field you will just need to
add key ref with that field and you are done.
MongoDB
MongoDB would be great when one of your key from one JSON object is to be
referenced to mutiple JSON object by just adding that field name in ref (ref:
'user')
Please vote this answer so that someone in need finds this answer and can get when MongoDB would be best suitable for them.
关于mysql - 我什么时候应该使用 mongoDB 而不是关系数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53681693/