We offer a platform for video- and audio-clips, photos and vector-grafics. We started with MySQL as the database backend and recently included MongoDB for storing all meta-information of the files, because MongoDB better fits the requirements. For example: photos may have Exif information, videos may have audio-tracks where we to want to store the meta-information of, too. Videos and vector-graphics don't share any common meta-information, etc. so I know, that MongoDB is perfect to store this unstructured data and keep it searchable.

然而,我们仍在继续开发我们的平台并添加新功能。接下来的步骤之一就是为我们的用户提供一个论坛。现在出现的问题是:使用MySQL数据库,这将是一个很好的选择,存储论坛和论坛帖子等或使用MongoDB,这也是?

所以问题是:什么时候使用MongoDB,什么时候使用RDBMS。如果可以选择,你会选择mongoDB还是MySQL,为什么会选择?


当前回答

在将MongoDb用于社交应用程序两年后,我已经见证了没有SQL RDBMS的真正意义。

You end up writing jobs to do things like joining data from different tables/collections, something that an RDBMS would do for you automatically. Your query capabilities with NoSQL are drastically crippled. MongoDb may be the closest thing to SQL but it is still extremely far behind. Trust me. SQL queries are super intuitive, flexible and powerful. MongoDb queries are not. MongoDb queries can retrieve data from only one collection and take advantage of only one index. And MongoDb is probably one of the most flexible NoSQL databases. In many scenarios, this means more round-trips to the server to find related records. And then you start de-normalizing data - which means background jobs. The fact that it is not a relational database means that you won't have (thought by some to be bad performing) foreign key constrains to ensure that your data is consistent. I assure you this is eventually going to create data inconsistencies in your database. Be prepared. Most likely you will start writing processes or checks to keep your database consistent, which will probably not perform better than letting the RDBMS do it for you. Forget about mature frameworks like hibernate.

我相信98%的项目使用典型的SQL RDBMS比使用NoSQL要好得多。

其他回答

谁需要分布式、分片的论坛?也许是Facebook,但除非你要创建一个Facebook的竞争对手,否则就使用Mysql, Postgres或任何你最熟悉的。如果您想尝试MongoDB,可以,但不要期望它为您创造奇迹。它会有它的怪癖和一般的肮脏,就像其他东西一样,如果你真的已经在研究它,我相信你已经发现了。

当然,MongoDB可能被大肆宣传,表面上看起来很简单,但您将遇到更成熟的产品已经克服的问题。不要那么容易被诱惑,而是等待“nosql”成熟,或者死亡。

就我个人而言,我认为“nosql”将会枯萎并死于碎片化,因为没有固定的标准(几乎是根据定义)。所以我个人不会在任何长期项目上下注。

在我的书中,唯一能拯救“nosql”的是,如果它能无缝地集成到Ruby或类似的语言中,并使语言“持久”,几乎没有任何编码和设计上的开销。这可能会发生,但我会等到那时候,而不是现在,当然它需要更成熟。

顺便问一下,你为什么要从零开始创建一个论坛?有大量的开源论坛可以调整以适应大多数需求,除非你真的在创建下一代论坛(我怀疑)。

在《NoSQL: If Only It Was That Easy》一书中,作者这样描述MongoDB:

MongoDB is not a key/value store, it’s quite a bit more. It’s definitely not a RDBMS either. I haven’t used MongoDB in production, but I have used it a little building a test app and it is a very cool piece of kit. It seems to be very performant and either has, or will have soon, fault tolerance and auto-sharding (aka it will scale). I think Mongo might be the closest thing to a RDBMS replacement that I’ve seen so far. It won’t work for all data sets and access patterns, but it’s built for your typical CRUD stuff. Storing what is essentially a huge hash, and being able to select on any of those keys, is what most people use a relational database for. If your DB is 3NF and you don’t do any joins (you’re just selecting a bunch of tables and putting all the objects together, AKA what most people do in a web app), MongoDB would probably kick ass for you.

然后,在结论部分:

The real thing to point out is that if you are being held back from making something super awesome because you can’t choose a database, you are doing it wrong. If you know mysql, just use it. Optimize when you actually need to. Use it like a k/v store, use it like a rdbms, but for god sake, build your killer app! None of this will matter to most apps. Facebook still uses MySQL, a lot. Wikipedia uses MySQL, a lot. FriendFeed uses MySQL, a lot. NoSQL is a great tool, but it’s certainly not going to be your competitive edge, it’s not going to make your app hot, and most of all, your users won’t care about any of this. What am I going to build my next app on? Probably Postgres. Will I use NoSQL? Maybe. I might also use Hadoop and Hive. I might keep everything in flat files. Maybe I’ll start hacking on Maglev. I’ll use whatever is best for the job. If I need reporting, I won’t be using any NoSQL. If I need caching, I’ll probably use Tokyo Tyrant. If I need ACIDity, I won’t use NoSQL. If I need a ton of counters, I’ll use Redis. If I need transactions, I’ll use Postgres. If I have a ton of a single type of documents, I’ll probably use Mongo. If I need to write 1 billion objects a day, I’d probably use Voldemort. If I need full text search, I’d probably use Solr. If I need full text search of volatile data, I’d probably use Sphinx.

我喜欢这篇文章,我发现它信息丰富,它很好地概述了NoSQL的前景和炒作。但是,这是最重要的部分,当涉及到在RDBMS和NoSQL之间进行选择时,问自己正确的问题真的很有帮助。恕我直言,值得一读。

文章的替代链接

如果需要复杂的事务,我会建议使用RDBMS。否则我会选择MongoDB,它工作起来更灵活,你知道它可以在你需要的时候扩展。(虽然我有偏见-我在MongoDB项目工作)

你知道,所有这些关于连接和“复杂事务”的东西——但许多年前是Monty自己解释了COMMIT / ROLLBACK的“必要性”,他说“所有这些都是在逻辑类(而不是数据库)中完成的”——所以这是同样的事情。我们所需要的是一个愚蠢但非常整洁和快速的数据存储/检索引擎,用于99%的web应用程序。

来存储这些非结构化数据

正如你所说,MongoDB最适合存储非结构化数据。这可以将数据组织成文档格式。这些被称为NoSQL数据存储(MongoDB、CouchDB、Voldemort)的RDBMS替代品对于大规模扩展的应用程序非常有用,并且需要从这些大数据存储中更快地访问数据。

而且这些数据库的实现比常规的RDBMS简单。由于这些是简单的键值或文档样式二进制对象,直接序列化到磁盘中。 这些数据存储不强制ACID属性和任何模式。这没有提供任何事务处理功能。因此,这可以扩大规模,我们可以实现更快的访问(读和写)。

但与之相反,RDBM在数据上强制执行ACID和模式。如果想要处理结构化数据,可以使用RDBM。

我会选择MySQL来创建这类论坛。因为这个规模不会很大。这是一个非常简单(常见)的应用程序,它具有数据之间的结构化关系。