1

I've try to get env variables via mongo-initi.js and mongo docker-compose.yml , If it is possible to get mongodb docker containers env variable via mongo shell?

1 Answers1

2

Which shell do you use? The legacy mongo shell (I prefer term "classic shell") or the new mongosh?

In the new mongosh, it is easy. The mongosh is a Node.js shell, simply use process.env

In legacy shell mongo you can use undocumented function _getEnv() or you pass environment variable in --eval, for example

mongo --eval "var my_var = '$MY_VAR';" ...

See How to pass environment variable to mongo script

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110