How to print a sentence when users on the server run mongo shell?
For
By default
That's it! Save the file and run
In order to disable dangerous functionalities:
Sample output:
#mongodb #mongo #shell #mongorc
For
DBAs
to limit some dangerous functionalities like dropping a database or it can be a helpful message. Or a greeting message. Or even printing the default database that he is already connected to.By default
mongoDB
looks for a file named .mongorc.js
in your home directory. So create a file ~/.mongorc.js
and put a content like below inside of it:print("Hello! Welcome to Alireza company :)");
print("Your database is set to: " + db);
That's it! Save the file and run
mongo
in your terminal, the output should be similar to the following:$ mongo
MongoDB shell version v3.6.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.2
Your database is set to: test
Hello! Welcome to Alireza company :)
>
In order to disable dangerous functionalities:
var no = function() { print("oops! You are not allowed to drop anything!!");};
// Prevent dropping databases
db.dropDatabase = DB.prototype.dropDatabase = no;
// Prevent dropping collections
DBCollection.prototype.drop =no;
// Prevent dropping indexes
DBCollection.prototype.dropIndex = no;
Sample output:
> db.dropDatabase('bi')
oops! You are not allowed to drop anything!!.
NOTE:
You can disable loading your .mongorc.js
by using the --norc
option when starting the shell.#mongodb #mongo #shell #mongorc