How to load mongodb script file while prompting for password?

1k Views Asked by At

I'm trying to connect to a MongoDB database that requires a password while also loading and running a script file on the database. I want to do it all from the command line and have the mongo shell exit afterwards. My problem is that I cannot do both at the same time, e.g.

$ mongo example.com:10023/database -u username -p script.js

The above command will think that script.js is actually my password, which it of cause isn't. I want it to actually prompt me for my password after I enter the command.

How can I do that?

1

There are 1 best solutions below

1
On BEST ANSWER

Try moving the arguments around so that script.js does not follow your password parameter.

$mongo example.com:10023/database script.js -u username -p