配置Mongo Shell

自定义提示

方法:在mongo shell中设置变量prompt

例子1:
(1) 当前会话中直接输入

cmdCount = 1;
prompt = function() {
             return (cmdCount++) + "> ";
         }

(2) 效果
在这里插入图片描述
例子2:
(1) 当前会话中直接输入

host = db.serverStatus().host;

prompt = function() {
             return db+"@"+host+"$ ";
         }

(2) 效果
在这里插入图片描述
例子3:
(1) 当前会话中直接输入

prompt = function() {
           return "Uptime:"+db.serverStatus().uptime+" Documents:"+db.stats().objects+" > ";
         }

(2) 效果
在这里插入图片描述
备注:只在当前会话有效

在Mongo Shell¶中使用外部编辑器

在启动mongo shell之前,可以通过设置editor环境变量在mongo shell中使用自己的编辑器。

export EDITOR=vim
mongo

在mongo shell中,可以通过键入edit或edit使用指定的编辑器进行编辑,如下例所示:

  1. 定义函数myFunction
function myFunction () { }
  1. 使用外部编辑器编辑函数
edit myFunction

该命令应打开VIM编辑会话。完成编辑后,保存并退出VIM编辑会话。

  1. 在mongoDB Shell中,输入函数名查看函数定义
> myFunction
function myFunction() {
	print("This was edited");
}

更改Mongo Shell批量大小

没看懂

db.collection.find()方法是从集合中检索文档的javascript方法。db.collection.find()方法将光标返回到结果中;但是,在mongo shell中,如果返回的光标没有使用var关键字分配给变量,那么光标将自动重复最多20次,以打印到与查询匹配的前20个文档。mongo shell将提示键入它,以便再重复20次。

可以设置dbquery.shellbatchsize属性,将文档数从默认值20更改为10,如下例所示:

DBQuery.shellBatchSize = 10;

翻译:https://docs.mongodb.com/manual/tutorial/configure-mongo-shell/

猜你喜欢

转载自blog.csdn.net/zhizhengguan/article/details/88636945