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. javascript - Underscore 与 函数式编程

    <Javascript函数式编程 PDF> # csdn下载地址http://download.csdn.net/detail/tssxm/9713727 Underscore # git ...

  2. 免费开源C# 论坛

    http://stackoverflow.com/questions/255591/who-knows-a-good-free-open-source-forum-in-c 1. http://yet ...

  3. 批量分发SSH秘钥

    #!/usr/bin/expect # filename: distribute_key.expif [ $argc != 2 ]{ send_user "usage: expect exp ...

  4. 【Nginx-反向代理server】基础知识(二)之多进程模式

    Nginx的多进程模式 nginx在启动后.会有一个master进程和多个worker进程.master进程主要用来管理worker进程,包括:接收来自外界的信号.向各worker进程发送信号,监控w ...

  5. Shell脚本与vi编辑器:vi启动与退出、工作模式、命令大全

    Vi简介 Vi是一种广泛存在于各种UNIX和Linux系统中的文本编辑程序. Vi不是排版程序,只是一个纯粹的文本编辑程序. Vi是全屏幕文本编辑器,它没有菜单,只有命令. Vi不是基于窗口的,所以, ...

  6. Unity3d Serialize问题

    备忘: 1. ScriptableOjbect中,由于Serialization的原因,不能使用基类引用来存储子类对象,这样都会导致数据丢失 2. 无法直接对Unity的数据如,vector3, qu ...

  7. 使用spring-boot-maven-plugin打包

    <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> ...

  8. java中Calendar.getInstance()和new Date()的差别是什么?

    java中Calendar.getInstance()和new Date()的差别如下: Calendar.getInstance()是获取一个Calendar对象并可以进行时间的计算,时区的指定ne ...

  9. Linux快速计算MD5和Sha1命令

    Linux计算MD5和Sha1的命令 MD5 MD5即Message-Digest Algorithm 5(信息-摘要算法 5),用于确保信息传输完整一致.是计算机广泛使用的杂凑算法之一(又译摘要算法 ...

  10. Android 编程之入门开发目录管理器开发抽屉与文件分类-4

    在此目录管理APP里,我们能够尝试引用一些新的元素.在这里我给打击介绍一个叫抽屉的布局,QQ就用到了抽屉布局.不 过他们又在原有的基础上自己开发了新的抽屉布局.而且还蛮高大上的,顺便说说分类管理.这些 ...