mysql - 我什么时候应该使用 mongoDB 而不是关系数据库

标签 mysql node.js mongodb express mern

我学习了一些关于 NodeJS/ExpressReactJS/Redux 的 udemy 类(class),其中一些类(class)是 MERN STACK,我'我真的很喜欢它们。但是讲师唯一没有真正解释的是 MongoDB 的选择。在参加这些类(class)之前,我总是使用 PostgreSQLMariaBD 用于我所有的项目持久层。现在我只是在所有这些类(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/

相关文章:

php - Doctrine2 重复键名错误

php - 计算用户总讨论次数的最佳方法是什么?

mysql - cakePHP 中使用 desc 进行数据排序

php - Docker:MySQL容器绑定(bind)主机mysqld套接字

mysql - Node.js promise 和错误处理。这不能做得更干净吗?

java - 在 AWS Lambda 上解析 Excel 文档

node.js - 为什么当我从数据库中检索我的小猫时它们不能说话

javascript - 无法使用 node.js 根据 MongoDB 中的特定字符串对值进行分组?

MongoDB:如何获取数组中特定子字段及其后续字段的值?

mongodb - 在 MongoDb 中返回没有其键的对象