Is it possible to add environment variables to Mon

2019-06-26 04:06发布

问题:

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:

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.

Best regards

回答1:

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

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

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.



回答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.