database MongoDB 数据库中的数据如何存储在磁盘上?

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

How is the data in a MongoDB database stored on disk?

mongodbdatabase

提问by Mark LeMoine

I know that MongoDBaccepts and retrieves records as JSON/BSON objects, but how does it actually store these files on disk? Are they stored as a collection of individual *.jsonfiles or as one large file? I have a hunch as to the latter, since the MongoDBdocs state that it works best on systems with ext4/xfs, which are better at handling large files. Can anyone confirm?

我知道MongoDB接受和检索记录为JSON/BSON objects,但它实际上如何将这些文件存储在磁盘上?它们是作为单个*.json文件的集合存储还是作为一个大文件存储?我对后者有一种预感,因为MongoDB文档指出它在带有 的系统上效果最佳ext4/xfs,后者更擅长处理大文件。有人可以确认吗?

采纳答案by brianz

A given mongo database is broken up into a series of BSON files on disk, with increasing size up to 2GB. BSON is its own format, built specifically for MongoDB.

一个给定的 mongo 数据库被分解成一系列磁盘上的 BSON 文件,大小增加到 2GB。BSON 是它自己的格式,专为 MongoDB 构建。

These slides should answer all of your questions:

这些幻灯片应该可以回答您的所有问题:

http://www.slideshare.net/mdirolf/inside-mongodb-the-internals-of-an-opensource-database

http://www.slideshare.net/mdirolf/inside-mongodb-the-internals-of-an-opensource-database

回答by Jamie Rumbelow

MongoDB stores the data on the disk as BSON in your data path directory, which is usually /data/db. There should be two files per collection there, collection.0, which stores the data (and that integer is then incremented as needs be) and collection.nswhich stores the namespacing metadata for the collection.

MongoDB 将磁盘上的数据作为 BSON 存储在您的数据路径目录中,通常是/data/db。每个集合应该有两个文件,collection.0存储数据(然后该整数根据需要递增)和collection.ns存储集合的命名空间元数据。

回答by MGriesbach

Detailed documentation of the BSON format can be found here: http://bsonspec.org/

BSON 格式的详细文档可以在这里找到:http: //bsonspec.org/

回答by Vikas Jadhav

Up to mongodb 3.0 http://blog.mongolab.com/2014/01/how-big-is-your-mongodb/If you turn on wiredtiger storage engine in MongoDB 3.0 it will use wiredtiger storage model http://docs.mongodb.org/v3.0/core/storage/#storage-wiredtiger

最高 mongodb 3.0 http://blog.mongolab.com/2014/01/how-big-is-your-mongodb/如果您在 MongoDB 3.0 中打开了wiredtiger 存储引擎,它将使用wiredtiger 存储模型 http://docs。 mongodb.org/v3.0/core/storage/#storage-wiredtiger