是否可以将环境变量添加到MongoDB配置文件中?

时间:2021-06-22 22:47:44

I am configuring a MongoDB replica set using YAML syntax. However, I'd like to use MONGODB_HOME environment variable to point to the database:

我正在使用YAML语法配置MongoDB副本集。但是,我想使用MONGODB_HOME环境变量指向数据库:

storage:
  dbPath: "ENV['MONGODB_HOME']/data/db"

I've tried using %, $, etc, but without success. Is it possible to do so?

我尝试过使用%,$等,但没有成功。有可能这样做吗?

Just in case, I'm working under Windows 7 64 bit.

为了以防万一,我在Windows 7 64位下工作。

Best regards

2 个解决方案

#1


The MongoDB config file (as at 3.0) only allows for static configuration values.

MongoDB配置文件(在3.0中)仅允许静态配置值。

If you want to pass dynamic values you could invoke via the command line or a PowerShell script instead, eg:

如果要传递动态值,可以通过命令行或PowerShell脚本调用,例如:

mongod.exe --dbpath %HOME%\data\db

If you're planning on starting up multiple MongoDB server instances (for example, for different users) you'll also want to specify unique --port numbers to listen to.

如果您计划启动多个MongoDB服务器实例(例如,针对不同的用户),您还需要指定要侦听的唯一 - 端口号。

#2


I have had some success setting a location with

我已经成功设置了一个位置

volumes:
  - mongo:/data/db

As part of a docker-compose.yml, which means I don't have to use the --dbpath CL switch.

作为docker-compose.yml的一部分,这意味着我不必使用--dbpath CL开关。

#1


The MongoDB config file (as at 3.0) only allows for static configuration values.

MongoDB配置文件(在3.0中)仅允许静态配置值。

If you want to pass dynamic values you could invoke via the command line or a PowerShell script instead, eg:

如果要传递动态值,可以通过命令行或PowerShell脚本调用,例如:

mongod.exe --dbpath %HOME%\data\db

If you're planning on starting up multiple MongoDB server instances (for example, for different users) you'll also want to specify unique --port numbers to listen to.

如果您计划启动多个MongoDB服务器实例(例如,针对不同的用户),您还需要指定要侦听的唯一 - 端口号。

#2


I have had some success setting a location with

我已经成功设置了一个位置

volumes:
  - mongo:/data/db

As part of a docker-compose.yml, which means I don't have to use the --dbpath CL switch.

作为docker-compose.yml的一部分,这意味着我不必使用--dbpath CL开关。