了解 MongoDB BSON 文档大小限制 [英] Understanding MongoDB BSON Document size limit

查看:67
本文介绍了了解 MongoDB BSON 文档大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 MongoDB 权威指南:

From MongoDB The Definitive Guide:

大于 4MB(转换为 BSON 时)的文档不能保存到数据库中.这是一个有点随意的限制(并且可能是将来提出);它主要是为了防止不良的架构设计并确保一致的性能.

Documents larger than 4MB (when converted to BSON) cannot be saved to the database. This is a somewhat arbitrary limit (and may be raised in the future); it is mostly to prevent bad schema design and ensure consistent performance.

我不明白这个限制,这是否意味着包含大量评论的博客文章的文档恰好大于 4MB 不能存储为单个文档?

I don't understand this limit, does this mean that A Document containing a Blog post with a lot of comments which just so happens to be larger than 4MB cannot be stored as a single document?

这也计算嵌套文档吗?

如果我想要一个审核值更改的文档怎么办.(它最终可能会增长,超过 4MB 的限制.)

What if I wanted a document which audits the changes to a value. (It will eventually may grow, exceeding 4MB limit.)

希望有人能正确解释这一点.

Hope someone explains this correctly.

我刚刚开始阅读 MongoDB(我正在学习的第一个 nosql 数据库).

I have just started reading about MongoDB (first nosql database I'm learning about).

谢谢.

推荐答案

首先,这实际上是在下一版本中提升到 8MB16MB ...但我认为从这个角度来看,来自 10gen(开发 MongoDB)的 Eliot 说得最好:

First off, this actually is being raised in the next version to 8MB or 16MB ... but I think to put this into perspective, Eliot from 10gen (who developed MongoDB) puts it best:

大小已经官方 '提升' 到 16MB

The size has been officially 'raised' to 16MB

因此,在您的博客示例中,4MB 是实际上很多..例如,战争"的完整解压文本世界"只有 364k (html):http://www.gutenberg.org/etext/36

So, on your blog example, 4MB is actually a whole lot.. For example, the full uncompresses text of "War of the Worlds" is only 364k (html): http://www.gutenberg.org/etext/36

如果你的博文有那么长这么多评论,我一个不是去读它:)

If your blog post is that long with that many comments, I for one am not going to read it :)

对于引用,如果您专用 1MB对他们来说,你可以轻松拥有更多小于 10k(可能更接近 20k)

For trackbacks, if you dedicated 1MB to them, you could easily have more than 10k (probably closer to 20k)

所以除了真的很奇怪情况下,它会很好用.而在例外情况或垃圾邮件,我真的不要认为你想要一个 20mb 的对象反正.我认为将引用限制为15k 左右很有意义 不不管性能如何.或最不特殊的外壳,如果有的话发生.

So except for truly bizarre situations, it'll work great. And in the exception case or spam, I really don't think you'd want a 20mb object anyway. I think capping trackbacks as 15k or so makes a lot of sense no matter what for performance. Or at least special casing if it ever happens.

-艾略特

我认为您很难达到极限……而且随着时间的推移,如果您升级……您将越来越不用担心.

I think you'd be pretty hard pressed to reach the limit ... and over time, if you upgrade ... you'll have to worry less and less.

限制的要点是这样您就不会用完服务器上的所有 RAM(因为您需要将文档的所有 MB 加载到 RAM 中当您查询时.)

The main point of the limit is so you don't use up all the RAM on your server (as you need to load all MBs of the document into RAM when you query it.)

所以限制是普通系统上正常可用内存的一些百分比......这将逐年增加.

So the limit is some % of normal usable RAM on a common system ... which will keep growing year on year.

在MongoDB中存储文件的注意事项

如果您需要存储大于 16MB 的文档(或文件),您可以使用 GridFS API,它会自动将数据分解成段并将它们流回给您(从而避免大小限制/RAM 的问题.)

If you need to store documents (or files) larger than 16MB you can use the GridFS API which will automatically break up the data into segments and stream them back to you (thus avoiding the issue with size limits/RAM.)

GridFS 不是将文件存储在单个文档中,而是将文件分成多个部分或块,并将每个块存储为单独的文档.

Instead of storing a file in a single document, GridFS divides the file into parts, or chunks, and stores each chunk as a separate document.

GridFS 使用两个集合来存储文件.一个集合存储文件块,另一个集合存储文件元数据.

GridFS uses two collections to store files. One collection stores the file chunks, and the other stores file metadata.

您可以使用此方法在数据库中存储图像、文件、视频等,就像在 SQL 数据库中一样.我什至用它来存储数 GB 的视频文件.

You can use this method to store images, files, videos, etc in the database much as you might in a SQL database. I have used this to even store multi gigabyte video files.

这篇关于了解 MongoDB BSON 文档大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆