mongo shell启动配置文件.mongorc.js(二)

mongo shell启动配置文件.mongorc.js(二)

如果你的主目录下有个.mongorc.js文件,那么当你启动shell时他就会自动运行。使用它可以初始化任何你经常使用的helper方法和你不想意外操作的删除方法。

比如,你不想使用默认的dropDatabase()方法了,你可以在.mongorc.js文件中添加下面的命令:

DB.prototype.dropDatabase = function() {   
    print("No dropping DBs!");    
}    
db.dropDatabase = DB.prototype.dropDatabase;

上面的例子改变了dropDatabase() helper方法,使他只打印出一行信息,而没有真正的删除数据库。

注意,这个技巧不是一个安全手段,固执的用户仍然可以在不使用helper前提下删除数据库。然而,移除危险的admin权限命令也可以帮助阻止“大堤的奔溃”。

几个建议在.mongorc.js中使用helper命令时移除的:

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

时间: 2024-08-03 10:55:57

mongo shell启动配置文件.mongorc.js(二)的相关文章

mongo shell启动配置文件.mongorc.js(三)

mongo shell启动配置文件.mongorc.js(三) 自定义MongoDB操作函数 可以把自己写的js代码保存在某个地方,让MongoDB加载它,然后就可以在MongoDB的命令行里操作它们. mongodb shell默认会加载~/.mongorc.js文件 例如以下修改了启动提示文字.左侧提示文字,增加了my_show_shards shell函数用于显示当前sharded collection的chunks在各分片的负载情况: //~/.mongorc.js   //show a

Linux shell 启动配置文件设置

安装一个软件,最后生成的报告中,要求“To start using the EGSnrc system, activate your current configuration by adding the following lines to your favorite shell resource file: ” 刚开始没明白Shell resource file是什么意思.后来搜索才发现原来就是环境变量的配置文件. 每个shell的启动,执行命令和程序的机制,如何处理命令和程序的输入输出,以

MongoDB - Introduction of the mongo Shell

Introduction The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mongo shell to query and update data as well as perform administrative operations. The mongo shell is a component of the MongoDB distributions. Once you h

MongoDB - The mongo Shell, Write Scripts for the mongo Shell

You can write scripts for the mongo shell in JavaScript that manipulate data in MongoDB or perform administrative operation. For more information about the mongo shell, see the Running .js files via a mongo shell Instance on the Server section for mo

《转》couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145

couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145,有须要的朋友能够參考下. 应为昨天安装的时候没及时截图,语言表达有点差,谅解 昨天在安装mongodb的时候无故出现 couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145 这种一个错误.后来google了下,基本都是说的没有正常关闭.产品了个mongod

count failed: not master{ "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" } at src/mongo/shell/query.js:191在SECONDARY节点无法show dbs

count failed: not master{ "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" } at src/mongo/shell/query.js:191 在SECONDARY节点无法show dbs 主从启动之后,连接slave可以成功连上,但是在slave中执行 show dbs 的时候就报错了: QUERY Er

《转》couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145

couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145,有需要的朋友可以参考下. 应为昨天安装的时候没及时截图,语言表达有点差,谅解 昨天在安装mongodb的时候无故出现 couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145 这样的一个错误,后来google了下,基本都是说的没有正常关闭,产品了个mongo

[Mongo]couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112

今天在启动mongo时候出现了一个错误,我的是win7环境. E:\server>mongo MongoDB shell version: 2.4.5-pre- connecting to: test Mon Sep 22 13:35:05.335 JavaScript execution failed: Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112 exception: co

解决couldn't connect to server 172.21.4.208:27 017 at src/mongo/shell/mongo.js:147

使用mongo命令访问数据库,出现如下所示的错误: 直接删除mongod.lock, rm -f /usr/local/mongodb/data/db/mongod.lock 注:使用此方法数据库内容会被删除. 其他方法访问:https://blog.csdn.net/wangli61289/article/details/44459467 然后再启动mongodb service mongodb start 解决couldn't connect to server 172.21.4.208:2