Get the App
SLTechnology News&Howtos  ›  Database  › 

Mongo shell startup configuration file .mongorc.js (2)

Shulou Source: shulou.com Published: 2022-06-01 08:11:17 09月15日 Update

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

Tags: Methods files commands data databases facets configurations dangers security accidents one line below examples information premises embankments suggestions means techniques permissions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology NVidia Linux macOS OPPO Reno