How to be authenticated autimatically in the MongoDB shell?

Add to ~/.mongorc.js:

db = connect('localhost:27017/<authentication database>');
db.auth('<admin>', '<password>');

stackoverflow.com/a/47894057