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,为什么会选择?


当前回答

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

其他回答

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

就像之前说的, 你可以在很多选择中选择,看看所有的选择: http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis

我的建议是找到你的最佳组合: 如果你需要ACID并且想要连接一些表,MySQL + Memcache真的很好 MongoDB + Redis是完美的文档存储 Neo4J是完美的图形数据库

我做什么:我开始使用MySQl + Memcache,因为我习惯了,然后我开始使用其他数据库框架。在一个项目中,你可以结合MySQL和MongoDB为例!

来存储这些非结构化数据

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

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

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

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

在《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之间进行选择时,问自己正确的问题真的很有帮助。恕我直言,值得一读。

文章的替代链接

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