MongoDB常用参数可以由config配置文件统一设置实现。mongod的配置文件为:mongod.yaml;mongos的配置文件尾mongos.yaml。如果要使用配置文件,需要先创建该文件。
https://docs.mongodb.com/v3.6/reference/configuration-options/
https://docs.mongodb.com/v4.0/reference/configuration-options/
以上是3.6版本和4.0版本的官方文档。
systemLog:
quiet: false
path: D:\MongoDB\mongodata\log\mongod.log
#日志文件
logAppend: false
destination: file
net:
bindIp: 127.0.0.1
#定义IP地址
port: 27017
#定义访问端口号
maxIncomingConnections: 65536
#定义最大连接数
wireObjectCheck: true
ipv6: false
#不支持IPV6
storage:
dbPath: D:\MongoDB\mongodata\db
#数据库位置
indexBuildRetry: true
journal:
enabled: true
directoryPerDB: false
engine: wiredTiger
#存储引擎选择
syncPeriodSecs: 60
# mmapv1:
# quota:
# enforced: false
# maxFilesPerDB: 8
# smallFiles: true
# journal:
# commitIntervalMs: 100
#这里要注意,mmapv1和wiredTiger只能选其一,3.0版本开始使用wiredTiger
wiredTiger:
engineConfig:
cacheSizeGB: 16
journalCompressor: snappy
directoryForIndexes: false
collectionConfig:
blockCompressor: snappy
indexConfig:
prefixCompression: true
operationProfiling:
slowOpThresholdMs: 100
mode: off
#副本集和分片集群未启用
#replication:
# oplogSizeMB: 10240
# replSetName: rs0
# secondaryIndexPrefetch: all
#sharding:
# clusterRole: shardsvr
# archiveMovedChunks: true
另外,在测试中发现,文件后缀不一定是.yaml。用.config也可以,只是定义成yaml格式。
下面这个形式也可以用:
## 增加配置文件内容
pidfilepath = D:\MongoDB\mongodata\log\configsrv.pid
dbpath = D:\MongoDB\mongodata\db
logpath = D:\MongoDB\mongodata\log\mongod.log
logappend = true
bind_ip = 0.0.0.0
#IP不做限制
port = 21000
#端口号
#declare this is a config db of a cluster;
#configsvr = true
#副本集名称
#replSet=configs
#设置最大连接数
maxConns=20000
这个2.4及之前版本的一个写法,说明如下:
File Format
Changed in version 2.6: MongoDB 2.6 introduced a YAML-based configuration file format. The 2.4 configuration file format remains for backward compatibility.
MongoDB configuration files use the YAML format [1].
具体官方文档如下:
https://docs.mongodb.com/v2.4/reference/configuration-options/




