如何在mongodb上配置storage.smallFiles

如何在mongodb上配置storage.smallFiles,mongodb,Mongodb,我有一台安装了mongodb的CentOS机器,我希望它始终使用storage.smallFiles设置,因此我转到/etc,创建了一个新文件/etc/mongodb.conf,在其中添加了以下文本并保存: storage: smallFiles: enabled: true 然后我键入: $ mongod --config /etc/mongodb.conf Unrecognized option: storage.smallFiles.enabled try 'mongo

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

storage:
   smallFiles:
      enabled: true
然后我键入:

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

我遵循了

的文档,存储选项的配置在不同版本的MongoDB中是不同的

MongoDB 3.0–4.0-:

请注意,MongoDB 4.0中不推荐使用MMAPv1存储引擎,它将在将来的版本中删除-

MongoDB 2.6-:

MongoDB 2.4-:

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

db.runCommand({getCmdLineOpts:1});
您也可以在启动mongod时直接指定它,但这样做无法实现配置文件的目的:

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

如果你是一个开发人员,没有时间,正在使用一个虚拟机,空间不够。。。只需复制、粘贴并继续

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

如果您使用的是mongodb:3.0

您需要将选项层次结构设置为storage.mmapv1.smallFiles:true

storage:
  mmapv1:
    smallFiles: true
注意yaml文件中的空格

例如:

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

如果您在mongodb 4.2中遇到此错误,那么这是因为在mongodb 4.2中删除了一些选项

Removed Configuration File Setting           Removed Command-line Option
storage.mmapv1.journal.commitIntervalMs  
storage.mmapv1.journal.debugFlags              mongod --journalOptions
storage.mmapv1.nsSize                          mongod --nssize
storage.mmapv1.preallocDataFiles               mongod --noprealloc
storage.mmapv1.quota.enforced                  mongod --quota
storage.mmapv1.quota.maxFilesPerDB             mongod --quotaFiles
storage.mmapv1.smallFiles                      mongod --smallfiles
storage.repairPath                             mongod --repairpath
replication.secondaryIndexPrefetch             mongod --replIndexPrefetch

请参阅mongodb 2.6.10中的

,我必须使用
smallfiles=true
@jtbr可能您仍然使用2.4中的旧格式。Mongo2.6引入了基于YAML的配置文件格式。保留旧格式以实现向后兼容性。
storage:
  mmapv1:
    smallFiles: true
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
  mmapv1:
    smallFiles: true
Removed Configuration File Setting           Removed Command-line Option
storage.mmapv1.journal.commitIntervalMs  
storage.mmapv1.journal.debugFlags              mongod --journalOptions
storage.mmapv1.nsSize                          mongod --nssize
storage.mmapv1.preallocDataFiles               mongod --noprealloc
storage.mmapv1.quota.enforced                  mongod --quota
storage.mmapv1.quota.maxFilesPerDB             mongod --quotaFiles
storage.mmapv1.smallFiles                      mongod --smallfiles
storage.repairPath                             mongod --repairpath
replication.secondaryIndexPrefetch             mongod --replIndexPrefetch