Convert Command-Line Options to YAML

    Starting in MongoDB 4.2, mongod and mongos accept --outputConfig command-line option to output the configuration used by the mongod/mongos instance.

    You can use this option to convert command-line options to YAML configuration.

    Examples

    Convert mongod Command-Line Options to YAML

    Consider the following mongod invocation that uses the command-line options:

    1. mongod --shardsvr --replSet myShard --dbpath /var/lib/mongodb --bind_ip localhost,My-Example-Hostname --fork --logpath /var/log/mongodb/mongod.log --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile /path/to/my/CA/file --tlsCertificateKeyFile /path/to/my/certificate/file --tlsClusterFile /path/to/my/cluster/membership/file

    Include the --outputConfig command-line option to generate the corresponding YAML file.

    copycopied

    1. mongod --shardsvr --replSet myShard --dbpath /var/lib/mongodb --bind_ip localhost,My-Example-Hostname --fork --logpath /var/log/mongodb/mongod.log --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile /path/to/my/CA/file --tlsCertificateKeyFile /path/to/my/certificate/file --tlsClusterFile /path/to/my/cluster/membership/file --outputConfig

    The mongod outputs the following YAML to stdout and exits:

    copycopied

    1. net:
    2. bindIp: localhost,My-Example-Hostname
    3. tls:
    4. CAFile: /path/to/my/CA/file
    5. certificateKeyFile: /path/to/my/certificate/file
    6. clusterFile: /path/to/my/cluster/membership/file
    7. mode: requireTLS
    8. outputConfig: true
    9. processManagement:
    10. fork: true
    11. replication:
    12. replSet: myShard
    13. security:
    14. clusterAuthMode: x509
    15. sharding:
    16. clusterRole: shardsvr
    17. storage:
    18. dbPath: /var/lib/mongodb
    19. systemLog:
    20. destination: file
    21. path: /var/log/mongodb/mongod.log

    To create a configuration file, copy the generated content into a file and delete the outputConfig setting from the YAML.

    Convert mongos Command-Line Options to YAML

    Consider the following mongos invocation that uses the command-line options:

    1. mongos --configdb myCSRS/cfg1.example.net:27019,cfg2.example.net:27019 --bind_ip localhost,My-Example-MONGOS-Hostname --fork --logpath /var/log/mongodb/mongos.log --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile /path/to/my/CA/file --tlsCertificateKeyFile /path/to/my/certificate/file --tlsClusterFile /path/to/my/cluster/membership/file

    Include the --outputConfig command-line option to generate the corresponding YAML for the mongos instance:

    copycopied

    1. mongos --configdb myCSRS/cfg1.example.net:27019,cfg2.example.net:27019 --bind_ip localhost,My-Example-MONGOS-Hostname --fork --logpath /var/log/mongodb/mongos.log --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile /path/to/my/CA/file --tlsCertificateKeyFile /path/to/my/certificate/file --tlsClusterFile /path/to/my/cluster/membership/file --outputConfig

    The mongos outputs the following YAML to stdout and exits:

    copycopied

    1. net:
    2. bindIp: localhost,My-Example-MONGOS-Hostname
    3. tls:
    4. CAFile: /path/to/my/CA/file
    5. certificateKeyFile: /path/to/my/certificate/file
    6. clusterFile: /path/to/my/cluster/membership/file
    7. mode: requireTLS
    8. outputConfig: true
    9. processManagement:
    10. fork: true
    11. security:
    12. clusterAuthMode: x509
    13. sharding:
    14. configDB: myCSRS/cfg1.example.net:27019,cfg2.example.net:27019
    15. systemLog:
    16. destination: file
    17. path: /var/log/mongodb/mongos.log

    To create a configuration file, copy the generated content into a file and delete the outputConfig setting from the YAML.

    参见

    原文 - Convert Command-Line Options to YAML