如何在 mongodb 上配置 storage.smallFiles

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

How to configure storage.smallFiles on mongodb

mongodb

提问by user3665192

I have a CentOS machine where I installed mongodb and I want it to always use storage.smallFiles setting, so I went to /etcand I created a new file /etc/mongodb.confwhere I added the following text and I saved:

我有一台安装了 mongodb 的 CentOS 机器,我希望它始终使用 storage.smallFiles 设置,所以我去/etc创建了一个新文件/etc/mongodb.conf,在其中添加了以下文本并保存:

storage:
   smallFiles:
      enabled: true

then I typed:

然后我输入:

$ mongod --config /etc/mongodb.conf
Unrecognized option: storage.smallFiles.enabled
try 'mongod --help' for more information

I followed documentation on http://docs.mongodb.org/manual/reference/configuration-options/#storage.smallFiles

我遵循了http://docs.mongodb.org/manual/reference/configuration-options/#storage.smallFiles 上的文档

回答by Christian P

The configuration for storage option smallFilesis different in different versions of MongoDB.

存储选项的配置smallFiles在不同版本的 MongoDB 中有所不同。

MongoDB 3.0–4.0- docs:

MongoDB 3.0–4.0-文档

storage:
  mmapv1:
    smallFiles: true

Note that MMAPv1 storage engine is deprecated in MongoDB 4.0 and it will be removed in future releases - docs

请注意,MMAPv1 存储引擎在 MongoDB 4.0 中已弃用,并将在未来版本中删除 - docs

MongoDB 2.6- docs:

MongoDB 2.6-文档

storage:
   smallFiles: true

MongoDB 2.4- docs:

MongoDB 2.4-文档

smallfiles = true

You can check that your setting is properly set by calling this command against admindatabase:

您可以通过对admin数据库调用此命令来检查您的设置是否正确设置:

db.runCommand({getCmdLineOpts:1});

You can also specify it directly when starting mongod, but that defeats the purpose of having a config file:

您也可以在启动 mongod 时直接指定它,但这违背了拥有配置文件的目的:

mongod --config /etc/mongodb.conf --smallFiles

回答by Italo Borssatto

If you're a developer, don't have time and is using a VM getting out of space... Just copy, paste and go!

如果您是开发人员,没有时间并且正在使用空间不足的虚拟机...只需复制、粘贴即可!

sudo bash -c "echo \"smallfiles=true\" >> /etc/mongodb.conf"
sudo service mongodb restart

回答by Sarat Chandra

If you are using mongodb: 3.0.

如果您使用的是 mongodb:3.0。

You need to set the Option Hierarchy as storage.mmapv1.smallFiles : true

您需要将 Option Hierarchy 设置为 storage.mmapv1.smallFiles : true

storage:
  mmapv1:
    smallFiles: true

Take care of the spaces in your yaml file.

注意 yaml 文件中的空格。

Example:

例子:

storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
  mmapv1:
    smallFiles: true