在谈论 MongoDB 与 Cassandra 时,“面向文档”与键值是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3046001/
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-09 11:45:20  来源:igfitidea点击:

What does "Document-oriented" vs. Key-Value mean when talking about MongoDB vs Cassandra?

mongodbcassandranosql

提问by tesserakt

What does going with a document based NoSQL option buy you over a KV store, and vice-versa?

使用基于文档的 NoSQL 选项可以通过 KV 存储购买什么,反之亦然?

回答by Pascal Thivent

A key-value storeprovides the simplest possible data model and is exactly what the name suggests: it's a storage system that stores values indexed by a key. You're limited to query by key and the values are opaque, the store doesn't know anythingabout them. This allows very fast read and write operations (a simple disk access) and I see this model as a kind of non volatile cache (i.e. well suited if you need fast accesses by key to long-lived data).

一个key-value存储提供了最简单的数据模型和正是顾名思义:它是一个存储系统,用于存储值由密钥索引。你通过关键限于查询和值是不透明的,商店不知道任何关于他们。这允许非常快速的读写操作(简单的磁盘访问),我将这种模型视为一种非易失性缓存(即非常适合需要通过键快速访问长期数据)。

A document-oriented databaseextends the previous model and values are stored in a structuredformat (a document, hence the name) that the database can understand. For example, a document could be a blog post andthe comments andthe tags stored in a denormalized way. Since the data are transparent, the store can do more work (like indexing fields of the document) and you're not limited to query by key. As I hinted, such databases allows to fetch an entire page's data with a single query and are well suited for content oriented applications (which is why big sites like Facebook or Amazon like them).

面向文档的数据库延伸先前模型和值被存储在一结构化的格式(文件,因此得名),该数据库可以理解。例如,一个文档可以是一篇博客文章评论标签以非规范化的方式存储。由于数据是透明的,存储可以做更多的工作(比如索引文档的字段)并且您不限于按键查询。正如我所暗示的,此类数据库允许通过单个查询获取整个页面的数据,并且非常适合面向内容的应用程序(这就是 Facebook 或 Amazon 等大型网站喜欢它们的原因)。

Other kinds of NoSQL databases include column-oriented stores, graph databasesand even object databases. But this goes beyond the question.

其他类型的 NoSQL 数据库包括面向列的存储图形数据库甚至对象数据库。但这超出了问题的范围。

See also

也可以看看

回答by Niels Wind

Well, I've been investigating NoSQL myself the past month or so. I think it generally could be stated something like

嗯,过去一个月左右,我一直在研究 NoSQL。我认为通常可以这样说

  • KV stores doesnt know of the value content actually stored for a key
  • Document based lets you define secondary indexes within the value content, as the db knows the document structure (e.g. tags of a blog post).
  • NoSQL solutions each have specific features which should be taken into consideration, such as
    • Special datatypes in a KV store (e.g. sets with left/right pop/push like in redis)
    • easy scale up/down cluster as riak says it has (I havent tried it ... yet)
    • pluggable data store as in Voldemort
    • build-in web configuration and web app support like in CouchDB / couchapp
  • KV 存储不知道为密钥实际存储的值内容
  • 基于文档,您可以在值内容中定义二级索引,因为数据库知道文档结构(例如博客文章的标签)。
  • NoSQL 解决方案每个都有应该考虑的特定功能,例如
    • KV 存储中的特殊数据类型(例如在 redis 中设置具有左/右弹出/推送的集合)
    • 像 riak 所说的那样轻松扩展/缩小集群(我还没有尝试过……还没有)
    • 与伏地魔一样的可插拔数据存储
    • 内置 Web 配置和 Web 应用程序支持,如 CouchDB / couchapp

回答by Big Data Guy

A document-oriented database, or document store, is for storing, retrieving, and managing document-oriented information, which is semi-structured data.. Key- value store is inherit of Document Oriented database. The difference lies in the way the data is processed; in a key-value store the data is considered to be inherently opaque to the database, whereas a document-oriented system relies on internal structure in the document in order to extract metadata that the database engine uses for further optimization.

面向文档的数据库或文档存储用于存储、检索和管理面向文档的信息,它是半结构化数据。键值存储是对面向文档的数据库的继承。不同之处在于处理数据的方式;在键值存储中,数据被认为对数据库本质上是不透明的,而面向文档的系统依赖于文档中的内部结构来提取数据库引擎用于进一步优化的元数据。

If we deals about difference between MOngoDb and Cassandra. MongoDB acts much like a relational database. Its data model consists of a database at the top level, then collections which are like tables in MySQL (for example) and then documents which are contained within the collection, like rows in MySQL. Each document has a field and a value where this is similar to columns and values in MySQL. Fields can be simple key / value e.g. { 'name': 'David Mytton' } but they can also contain other documents e.g. { 'name': { 'first' : David, 'last' : 'Mytton' } }. In Cassandra documents are known as “columns” which are really just a single key and value. e.g. { 'key': 'name', 'value': 'David Mytton' }. There's also a timestamp field which is for internal replication and consistency. The value can be a single value but can also contain another “column”. These columns then exist within column families which order data based on a specific value in the columns, referenced by a key.

如果我们讨论 MONgoDb 和 Cassandra 之间的区别。MongoDB 的行为很像关系数据库。它的数据模型由顶层的数据库、类似于 MySQL 中的表的集合(例如)和包含在集合中的文档(如 MySQL 中的行)组成。每个文档都有一个字段和一个值,这类似于 MySQL 中的列和值。字段可以是简单的键/值,例如 { 'name': 'David Mytton' } 但它们也可以包含其他文档,例如 { 'name': { 'first' : David, 'last' : 'Mytton' } }。在 Cassandra 中,文档被称为“列”,它们实际上只是一个键和值。例如 { 'key': 'name', 'value': 'David Mytton' }。那里' s 也是一个时间戳字段,用于内部复制和一致性。该值可以是单个值,但也可以包含另一个“列”。然后这些列存在于列族中,这些列族根据列中的特定值对数据进行排序,由键引用。

But , At the top level there is a keyspace, which is similar to the MongoDB database.

但是,在顶层有一个keyspace,类似于MongoDB 数据库。