博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MongoDB - The mongo Shell, Configure the mongo Shell
阅读量:5213 次
发布时间:2019-06-14

本文共 3351 字,大约阅读时间需要 11 分钟。

Customize the Prompt

You may modify the content of the prompt by setting the variable prompt in the mongo shell. The promptvariable can hold strings as well as JavaScript code. If prompt holds a function that returns a string, mongo can display dynamic information in each prompt.

You can add the logic for the prompt in the  file to set the prompt each time you start up the  shell.

Customize Prompt to Display Number of Operations

For example,to create a mongo shell prompt with the number of operations issued in the current session, define the following variables in the mongo shell:

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

The prompt would then resemble the following:

1> 2> 3>

Customize Prompt to Display Database and Hostname

To create a mongo shell prompt in the form of <database>@<hostname>$, define the following variables:

3> prompt = "> "> host = db.serverStatus().host;huey> prompt = function() {... return db+"@"+host+"$ ";... }function () {return db+"@"+host+"$ ";}

The prompt would then resemble the following:

test@huey$

Customize Prompt to Display Up Time and Document Count

To create a  shell prompt that contains the system up time and the number of documents in the current database, define the following prompt variable in the  shell:

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

The prompt would then resemble the following:

Uptime:5897 Documents:6 >

 

Use an External Editor in the mongo Shell

You can use your own editor in the mongo shell by setting the  environment variable before starting the  shell.

export EDITOR=vimmongo

Once in the mongo shell, you can edit with the specified editor by typing edit <variable> or edit <function>, as in the following example:

  1. Define a function myFunction:
    function myFunction () { }
  2. Edit the function using your editor:
    edit myFunction

    The command should open the vim edit session. When finished with the edits, save and exit vim edit session.

  3. In the  shell, type myFunction to see the function definition:
    myFunction

    The result should be the changes from your saved edit:

    function myFunction() {    print("This was edited");}

NOTE: As mongo shell interprets code edited in an external editor, it may modify code in functions, depending on the JavaScript compiler. For mongo may convert 1+1 to 2 or remove comments. The actual changes affect only the appearance of the code and will vary based on the version of JavaScript used but will not affect the semantics of the code.

 

Change the mongo Shell Batch Size

The  method is the JavaScript method to retrieve documents from a . The  method returns a  to the results; however, in the  shell, if the returned cursor is not assigned to a variable using the var keyword, then the cursor is automatically iterated up to 20 times to print up to the first 20 documents that match the query. The  shell will prompt Type it to iterate another 20 times.

You can set the DBQuery.shellBatchSize attribute to change the number of documents from the default value of 20, as in the following example which sets it to 10:

DBQuery.shellBatchSize = 10;

 

转载于:https://www.cnblogs.com/huey/p/6120258.html

你可能感兴趣的文章
ztree实现拖拽移动和复制
查看>>
layui父页面执行子页面方法
查看>>
redis的window版本下载地址
查看>>
win运行canal
查看>>
idea右下角显示使用内存情况
查看>>
修改系统个人文件夹存储默认存放位置
查看>>
win10电脑休眠后无法唤醒的解决办法
查看>>
如何破解域管理员密码
查看>>
Windows Server 2008 R2忘记管理员密码后的解决方法
查看>>
IE11兼容IE8的设置
查看>>
windows server 2008 R2 怎么集成USB3.0驱动
查看>>
企业邮箱 Webmail 通讯录导入 Outlook
查看>>
Foxmail:导入联系人
查看>>
在windows上安装ubuntu双系统
查看>>
JavaScript AJAX原生写法
查看>>
详解promise、async和await的执行顺序
查看>>
NodeJs实现WebSocket——express-ws
查看>>
vue开发公众号 在钩子里面处理登录获取code
查看>>
vue路由跳转时更改页面title
查看>>
NodeJS怎么实现WebSocket功能
查看>>