MONGO Shell startup configuration file. Mongorc.js (ii)

Source: Internet
Author: User
Tags mongo shell

MONGO Shell startup configuration file. Mongorc.js (ii)


If you have a. mongorc.js file under your home directory, he will run automatically when you start the shell. Use it to initialize any helper methods you use frequently and delete methods that you do not want to accidentally manipulate.


For example, you do not want to use the default Dropdatabase () method, and 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 he prints only one line of information without actually deleting the database.

Note that this technique is not a security measure, and the stubborn user can still delete the database without using the helper. However, removing the dangerous admin Privilege command can also help prevent the "collapse of the Levee."


Several recommendations are removed when using the helper command in. Mongorc.js:

DB.prototype.shutdownServer
DBCollection.prototype.drop
DBCollection.prototype.ensureIndex
DBCollection.prototype.reIndex
DBCollection.prototype.dropIndexes

This article is from the SQL Server deep dives blog, so be sure to keep this source http://ultrasql.blog.51cto.com/9591438/1707353

MONGO Shell startup configuration file. Mongorc.js (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.