Customize the Prompt 自定义提示

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

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

大概的意思:你可以通过修改mongorc.js这个文件来让你的终端提示符变得不太一样

注意:

# vim /root/.mongorc.js

如果使用yum 装的,这个文件在/root/目录下

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;
prompt = 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:

host = db.serverStatus().host;

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

The prompt would then resemble the following:

test@myHost1$

Customize Prompt to Display Up Time and Document Count

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

prompt = 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 EDITOR environment variable before starting the mongo shell.

export EDITOR=vim
mongo

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 mongo 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.

以上大概的意思是:通过集中方式来设置显示的方式,需要注意的是mong shell的解释器会依赖于js的版本,即使你使用了编辑器,还是依靠于js的解释器。它只会影响代码的展现而不会影响代码本身的意思

Change the mongo Shell Batch Size

The db.collection.find() method is the JavaScript method to retrieve documents from a collection. Thedb.collection.find() method returns a cursor to the results; however, in the mongo 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 mongo shell will prompt Typeit 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;
大概的意思是:因为在mongo shell中,默认只会将前面20条的结果显示出来,修改默认的显示迭代次数,可以使用
DBQuery.shellBatchSize来设置

1.Configure the mongo Shell-官方文档摘录的更多相关文章

  1. 2.Access the mongo Shell Help-官方文档摘录

    总结: 1.使用help可以查看帮助信息db.help()  help等 2.查看对应的实现方法.比如 test@gzxkvm52$ db.updateUser function (name, upd ...

  2. Cocos Creator 加载和切换场景(官方文档摘录)

    Cocos Creator 加载和切换场景(官方文档摘录) 在 Cocos Creator 中,我们使用场景文件名( 可以不包含扩展名)来索引指代场景.并通过以下接口进行加载和切换操作: cc.dir ...

  3. ng的概念层次(官方文档摘录)

    官方文档是这么说的: You write Angular applications by: composing HTML templates with Angularized markup, writ ...

  4. Cocos Creator 使用计时器(官方文档摘录)

    在 Cocos Creator 中,我们为组件提供了方便的计时器,这个计时器源自于 Cocos2d-x 中的 cc.Scheduler,我们将它保留在了 Cocos Creator 中并适配了基于组件 ...

  5. Cocos Creator 生命周期回调(官方文档摘录)

    Cocos Creator 为组件脚本提供了生命周期的回调函数.用户通过定义特定的函数回调在特定的时期编写相关 脚本.目前提供给用户的声明周期回调函数有: onLoad start update la ...

  6. angular 模板语法(官方文档摘录)

    https://angular.cn/guide/template-syntax {{}} 和"" 如果嵌套,{{}}里面求完值,""就是原意 <h3&g ...

  7. Spring Data Commons 官方文档学习

    Spring Data Commons 官方文档学习   -by LarryZeal Version 1.12.6.Release, 2017-07-27 为知笔记版本在这里,带格式. Table o ...

  8. 【翻译】Django Channels 官方文档 -- Tutorial

    Django Channels 官方文档 https://channels.readthedocs.io/en/latest/index.html 前言: 最近课程设计需要用到 WebSocket,而 ...

  9. hbase官方文档(转)

    FROM:http://www.just4e.com/hbase.html Apache HBase™ 参考指南  HBase 官方文档中文版 Copyright © 2012 Apache Soft ...

  10. HBase官方文档

    HBase官方文档 目录 序 1. 入门 1.1. 介绍 1.2. 快速开始 2. Apache HBase (TM)配置 2.1. 基础条件 2.2. HBase 运行模式: 独立和分布式 2.3. ...

随机推荐

  1. MYSQL版查询分页存储过程

    /*--名称:MYSQL版查询分页存储过程 --输入参数:@fields -- 要查询的字段用逗号隔开--输入参数:@tables -- 要查询的表--输入参数:@where -- 查询条件--输入参 ...

  2. Mac OS X中配置Apache后提示You don't have permission to access / on this server

    根据这篇博客http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.html,在mac系统中,配置的apache,配置完成后,提示 You d ...

  3. C# 匿名类型 分组 求和

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. 比isConnected()更靠谱的的获取socket实时连接状态!

    看到这个标题,预计非常多人会说用socket.isConnected()或者socket.isClosed()等方法来推断即可了,但其实这些方法都是訪问socket在内存驻留的状态,当socket和s ...

  5. java获取真实的ip地址

    直接上代码,获取请求主机的IP地址,如果通过代理进来,则透过防火墙获取真实IP地址 public class IPUtil { private static final Logger logger = ...

  6. 《排序算法》——堆排序(大顶堆,小顶堆,Java)

    十大算法之堆排序: 堆的定义例如以下: n个元素的序列{k0,k1,...,ki,-,k(n-1)}当且仅当满足下关系时,称之为堆. " ki<=k2i,ki<=k2i+1;或k ...

  7. vbox安装ubuntu之后挂载共享文件夹无权限访问的问题以及改了主机名,导致命令行不能解析主机名的问题

    1.挂载方法在挂载的时候虚拟机给出了命令 2. sudo adduser yourusername vboxsf (vboxsf是挂载的文件夹的用户组,在/media目录下用 ls -l 命令可以看到 ...

  8. jQuery导入代码片段并绑定事件

    a.html <div> <button class="button" >点我达</button> </div> b.html &l ...

  9. hdu1533 Going Home 最小费用最大流 构造源点和汇点

    Going Home Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  10. 关于LNMP服务器 Thinkphp5验证码不显示问题

    关于LNMP服务器 Thinkphp5验证码不显示问题   浏览:246 发布日期:2017/09/20 分类:ThinkPHP5专区 关键字: thinkphp验证码不显示 nginx下验证码不显示 ...