2

Is there a way to access shell env variable in the mongo shell?
In nodejs, it can access an environment variable in script like following.

var uri = process.env['MONGOLAB_URI']

I am looking for the same way in mongo script.

Hill
  • 3,391
  • 3
  • 24
  • 28
  • Possible duplicate of [How to pass environment variable to mongo script](https://stackoverflow.com/questions/39444467/how-to-pass-environment-variable-to-mongo-script) – Matthew Mar 25 '19 at 14:46

1 Answers1

2

You can use a redirection like this :

NAME="John"

mongo << EOF
use testDB
db.person.findOne({"name":"$NAME"})
EOF
Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159