Last Updated: February 25, 2016
·
1.975K
· petems

Add a Banner to Mongo shell

So, you've got your mongodb setup, everything's ready to go! BUT you suddenly remember you have a security requirement that you have to add a banner to all your databases, oh no! What to do?

Currently, the best way I've found out how to do this is this:

Create/edit your ~/.mongorc.js file, and add a line like this:

mongo_shell_banner = "" +
"*******************************************************************************\n" +
"                      UNAUTHORISED ACCESS PROHIBITED                           \n" +
"*******************************************************************************\n" +
"                                                                   \n" +
"Access to this database is restricted; you may not access data on this system  \n" +
"unless explicitly authorised, in accordance with Laws XYZ etc.                 \n" +
"                                                                \n" +
"*******************************************************************************\n" +
"                       UNAUTHORISED ACCESS PROHIBITED                          \n" +
"*******************************************************************************\n" +
""

print(mongo_shell_banner);

Then, next time you open up the mongo shell as that user, you'll be greeted with something like this:
Picture

However, this only applies to the user where the .mongorc.js is located. In the future, 10Gen are going to implent the use of a /etc/mongorc.js which is loaded first which should be coming in 2.5

Hope this helps!