mongodb - 了解 MongoDB BSON 文档大小限制

来自 MongoDB 权威指南:

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 的博客文章的文档不能存储为单个文档?

这也算嵌套文档吗?

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

希望有人正确解释这一点。

我刚刚开始阅读有关 MongoDB(我正在学习的第一个 nosql 数据库)的信息。

谢谢。

最佳答案

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

编辑: 大小为 officially “提升”到 16MB

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 :)

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

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.

-Eliot

我认为你很难达到极限......随着时间的推移,如果你升级......你会越来越少担心。

限制的要点是不要用尽服务器上的所有 RAM(因为您需要将文档的所有 MB 加载到 RAM 中当你查询它时。)

所以限制是通用系统上正常可用 RAM 的一些百分比......这将逐年增长。

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

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

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 uses two collections to store files. One collection stores the file chunks, and the other stores file metadata.

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

https://stackoverflow.com/questions/4667597/

相关文章:

database - 如何创建数据库的 MongoDB 转储?

mongodb - 什么时候应该使用 NoSQL 数据库而不是关系数据库?可以在同一个网站上使用两者

javascript - 我可以按日期查询 MongoDB ObjectId 吗?

mongodb - 如何解决 MongoDB 中缺少事务的问题?

linux - 在 linux/OS X 上启动 mongod 服务的正确方法是什么?

ios - MongoDB 与 Firebase

node.js - MongoDB/Mongoose 在特定日期查询?

mongodb - 如何在 MongoDB 中使用 Elasticsearch?

mongodb - 当案例类包含 Scala 枚举时,如何使用 Rogue 和 MongoCaseC

mongodb - 如何在一个命令中停止 mongo DB