database MongoDB 的优缺点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5244437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:06:15  来源:igfitidea点击:

Pros and cons of MongoDB?

mongodbperformancedatabase

提问by zbdiablo

Could anybody tell me what is the pros and cons of mongodb, especially comparing with the relational database? including ACID, scalability, throughput, main memory usage, insert/query performance and index size etc.

谁能告诉我 mongodb 的优缺点是什么,尤其是与关系数据库相比?包括 ACID、可扩展性、吞吐量、主内存使用、插入/查询性能和索引大小等。

回答by AdaTheDev

Some general points on MongoDB

关于 MongoDB 的一些一般观点

Pros:

优点:

  • schema-less. If you have a flexible schema, this is ideal for a document store like MongoDB. This is difficult to implement in a performant manner in RDBMS
  • ease of scale-out. Scale reads by using replica sets. Scale writes by using sharding (auto balancing). Just fire up another machine and away you go. Adding more machines = adding more RAM over which to distribute your working set.
  • cost. Depends on which RDBMS of course, but MongoDB is free and can run on Linux, ideal for running on cheaper commodity kit.
  • you can choose what level of consistency you want depending on the value of the data (e.g. faster performance = fire and forget inserts to MongoDB, slower performance = wait til insert has been replicated to multiple nodes before returning)
  • 无模式。如果您有一个灵活的模式,这非常适合像 MongoDB 这样的文档存储。这很难在 RDBMS 中以高性能的方式实现
  • 易于横向扩展。使用副本集扩展读取。通过使用分片(自动平衡)来扩展写入。只需启动另一台机器就可以了。添加更多机器 = 添加更多 RAM 来分发您的工作集。
  • 成本。当然取决于哪个 RDBMS,但 MongoDB 是免费的并且可以在 Linux 上运行,非常适合在更便宜的商品套件上运行。
  • 您可以根据数据的值选择所需的一致性级别(例如,更快的性能 = 触发并忘记插入到 MongoDB,更慢的性能 = 等待直到插入已复制到多个节点再返回)

Cons:

缺点:

  • Data size in MongoDB is typically higher due to e.g. each document has field names stored it
  • less flexibity with querying (e.g. no JOINs)
  • no support for transactions - certain atomic operations are supported, at a single document level
  • at the moment Map/Reduce (e.g. to do aggregations/data analysis) is OK, but not blisteringly fast. So if that's required, something like Hadoop may need to be added into the mix
  • less up to date information available/fast evolving product
  • MongoDB 中的数据大小通常更高,因为例如每个文档都存储了字段名称
  • 查询的灵活性较低(例如,没有 JOIN)
  • 不支持事务 - 在单个文档级别支持某些原子操作
  • 目前 Map/Reduce(例如进行聚合/数据分析)是可以的,但不是非常快。因此,如果需要,可能需要将 Hadoop 之类的东西添加到组合中
  • 可用信息较少/快速发展的产品

I recently blogged my thoughtson MongoDB as someone coming from SQL Server background, so you might be interested in that (above are just some of the main points).

我最近在博客中以 SQL Server 背景的人的身份发表了我对 MongoDB 的看法,因此您可能对此感兴趣(以上只是一些要点)。

If you're looking for a "Is MongoDB better than RDBMS" answer - then IMHO there is no answer. NoSQL technologies like MongoDB provide an alternative, that complements RDBMS technologies. One may be better suited to a particular purpose than the other, so it's all about making a call on what is best for you for a given requirement.

如果您正在寻找“MongoDB 是否比 RDBMS 更好”的答案 - 那么恕我直言,没有答案。MongoDB 等 NoSQL 技术提供了一种替代方案,可以补充 RDBMS 技术。一个可能比另一个更适合某个特定目的,所以这一切都是为了针对给定的要求做出最适合您的电话。