mongodb 基于文档和基于键/值的数据库之间的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3554169/
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
Difference between Document-based and Key/Value-based databases?
提问by never_had_a_name
I know there are three different, popular types of non-sql databases.
我知道有三种不同的、流行的非 sql 数据库类型。
- Key/Value: Redis, Tokyo Cabinet, Memcached
- ColumnFamily: Cassandra, HBase
- Document: MongoDB, CouchDB
- 键/值:Redis、东京内阁、Memcached
- 列族:Cassandra、HBase
- 文档:MongoDB、CouchDB
I have read long blogs about it without understanding so much.
我已经阅读了有关它的长篇博客,但并没有了解太多。
I know relational databases and get the hang around document-based databases like MongoDB/CouchDB.
我了解关系型数据库并熟悉基于文档的数据库,例如 MongoDB/CouchDB。
Could someone tell me what the major differences are between these and the 2 former on the list?
有人能告诉我这些和列表中的前两个之间的主要区别是什么吗?
采纳答案by Niels van der Rest
The main differences are the data model and the querying capabilities.
主要区别在于数据模型和查询功能。
Key-value stores
键值存储
The first type is very simple and probably doesn't need any further explanation.
第一种非常简单,可能不需要任何进一步的解释。
Data model: more than key-value stores
数据模型:不仅仅是键值存储
Although there is some debateon the correct name for databases such as Cassandra, I'd like to call them column-family stores. Although key-value pairs are an essential part of Cassandra, it's not limited to just that. It allows you to nest key-value pairs, so a key could refer to multiple sub-key-value pairs.
尽管对于 Cassandra 等数据库的正确名称存在一些争论,但我想称它们为column-family store。尽管键值对是 Cassandra 的重要组成部分,但它不仅限于此。它允许您嵌套键值对,因此一个键可以引用多个子键值对。
You cannot nest key-value pairs indefinitely though. You are limited to three levels (column families) or four levels of nesting (super-column families). In case the term column family doesn't ring a bell, see the WTF is a SuperColumnarticle, it's a good explanation of Cassandra's data model.
但是,您不能无限期地嵌套键值对。您仅限于三层(列族)或四层嵌套(超级列族)。如果术语列族没有响起,请参阅WTF 是一篇 SuperColumn文章,它很好地解释了 Cassandra 的数据模型。
Document databases, such as CouchDB and MongoDB store entire documents in the form of JSON objects. You can think of these objects as nested key-value pairs. Unlike Cassandra, you can nest key-value pairs as much as you want. JSON also supports arrays and understands different data types, such as strings, numbers and boolean values.
文档数据库,例如 CouchDB 和 MongoDB,以JSON 对象的形式存储整个文档。您可以将这些对象视为嵌套的键值对。与 Cassandra 不同,您可以根据需要嵌套键值对。JSON 还支持数组并理解不同的数据类型,例如字符串、数字和布尔值。
Querying
查询
I believe column-family stores can only be queried by key, or by writing map-reduce functions. You cannot query the values like you would in an SQL database. If your application needs more complex queries, your application will have to create and maintain indexes in order to access the desired data.
我相信列族存储只能通过键查询,或者通过编写 map-reduce 函数来查询。您不能像在 SQL 数据库中那样查询值。如果您的应用程序需要更复杂的查询,您的应用程序将必须创建和维护索引才能访问所需的数据。
Document databases support queries by key and map-reduce functions as well, but also allow you to do basic queries by value, such as "Give me all users with more than 10 posts". Document databases are more flexible in this way.
文档数据库也支持按键查询和 map-reduce 函数,但也允许你按值进行基本查询,例如“给我所有超过 10 个帖子的用户”。文档数据库以这种方式更加灵活。
回答by Ashraf Alam
Ayendehas given a nice explanation regarding the difference between Key-Value and Document database:
Ayende对 Key-Value 和 Document 数据库之间的区别给出了很好的解释:
A document database is, at its core, a key/value store with one major exception. Instead of just storing any blob in it, a document db requires that the data will be store in a formatthat the database can understand (i.e. JSON, XML etc). In most doc dbs, that means that we can now allow querieson the document data.
文档数据库的核心是一个键/值存储,但有一个主要例外。文档db 不仅要求在其中存储任何blob,还要求以数据库可以理解的格式(即JSON、XML 等)存储数据。在大多数文档数据库中,这意味着我们现在可以允许对文档数据进行查询。