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. 灰色预测--matlab&python实现

    function SGrey X0 = input('请输入原始负荷数据:'); %输入原始数据 n = length(X0); %原始n年数据 %累加生成 X1 = zeros(1,n); for ...

  2. Flume入门样例

    Flume 作为 cloudera 开发的实时日志收集系统,受到了业界的认可与广泛应用.Flume 初始的发行版本目前被统称为 Flume OG(original generation),属于 clo ...

  3. python中MySQL模块TypeError: %d format: a number is required, not str异常解决

    转载自:http://www.codeif.com/topic/896 python代码: attr_sql = "INSERT INTO `ym_attribute` (`attr_nam ...

  4. Eclipse Mylyn成为顶级项目

    http://www.infoq.com/cn/news/2010/09/eclipse-mylyn/ 作为应用程序的生命周期管理工具,Eclipse Mylyn项目已经被提升为顶级的Eclipse项 ...

  5. [UIDevice currentDevice].model

    iPhone Simulator iPad Simulator iPod touch iPad iPhone  

  6. Python MQTT客户端实现

    1.安装paho-mqtt 使用Python Package Index (PyPi) pip install paho-mqtt 使用virtualenv virtualenv paho-mqtt ...

  7. Android API Guides---OpenGL ES

    OpenGL ES Android包含高性能2D和3D图形开放图形库(OpenGL®的).详细而言,OpenGL ES的API支持. OpenGL是一个跨平台的图形API.用于指定的3D图形处理硬件标 ...

  8. 阿里云RDS备份的tar格式包恢复到本地自建数据库

    说明 阿里云RDS-mysql数据库是通过percona-Xtrabackup进行备份的,所以恢复时也需要安装该软件. 另外注意的是:你自己下载的MySQL版本要和阿里云上的MySQL版本一致,不然会 ...

  9. tic-tac-toe游戏代码

    package com.p4f.tictactoe.demo; import javax.swing.border.Border; public class Board { /** * positio ...

  10. raw flash vs FTL

    1. 区别 raw flash devices: NAND, NOR, OneNAND, etc,其被作为MTD设备处理(既不是字符设备,也不是块设备). FTL device:Flash Trans ...