Mongo shell startup configuration file .mongorc.js (2)
Mongo shell startup configuration file .mongorc.js (2)
If you have a .mongorc.js file in your home directory, it will run automatically when you start shell. Use it to initialize any helper methods you use frequently and delete methods that you don't want to accidentally operate on.
For example, instead of using the default dropDatabase () method, you can add the following command to the .mongorc.js file:
DB.prototype.dropDatabase = function () {print ("No dropping DBs!");} db.dropDatabase = DB.prototype.dropDatabase
The above example changes the dropDatabase () helper method so that it prints only one line of information without actually deleting the database.
Note that this technique is not a security tool, and stubborn users can still delete databases without using helper. However, the command to remove dangerous admin permissions can also help prevent the "collapse of the levee".
Several suggestions for removal when using the helper command in .mongorc.js:
DB.prototype.shutdownServer
DBCollection.prototype.drop
DBCollection.prototype.ensureIndex
DBCollection.prototype.reIndex
DBCollection.prototype.dropIndexes