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?
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 mongos
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';" ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.