Configure the mongo Shell-官方文档摘录

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:

[email protected]$

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来设置
时间: 2024-10-08 20:50:32

Configure the mongo Shell-官方文档摘录的相关文章

hbase官方文档(转)

Apache HBase™ 参考指南  HBase 官方文档中文版 Copyright © 2012 Apache Software Foundation.保留所有权利. Apache Hadoop, Hadoop, MapReduce, HDFS, Zookeeper, HBase 及 HBase项目 logo 是Apache Software Foundation的商标. Revision History Revision 0.95-SNAPSHOT 2012-12-03T13:38 中文版

Android Studio官方文档之构建和运行你的APP

Android Studio官方文档之构建和运行你的APP 本文由MTJH翻译,jkYishon审校. 前言 默认情况下,Android Studio设置新的项目并且部署到模拟器或者真机设备上,只需要点击几下.使用即时运行,你并不需要构建一个新的APK即可将改变后的方法和现有的应用资源应用到一个正在运行的应用程序中,所以代码的改变是即时可见的. 点击Run来构建并运行你的APP.Android Studio通过Gradle构建你的App,选择一个部署的设备(模拟器或连接的设备),然后把你的APP

Spring Cloud官方文档中文版-声明式Rest客户端:Feign

官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#spring-cloud-feign 文中例子我做了一些测试在:http://git.oschina.net/dreamingodd/spring-cloud-preparation Declarative REST Client: Feign 声明式Rest客户端:Feign Feign is a declarative web service client. It

Spring Cloud官方文档中文版-服务发现:Eureka客户端

官方文档地址为:http://cloud.spring.io/spring-cloud-static/Brixton.SR7/#_spring_cloud_netflix 文中例子我做了一些测试在:http://git.oschina.net/dreamingodd/spring-cloud-preparation Spring Cloud Netflix This project provides Netflix OSS integrations for Spring Boot apps th

Hive官方文档

Hive官方文档 内容列表 Cloudera制作的Hive介绍视频 安装与配置 系统需求 安装Hive发行版 从Hive源码编译 运行Hive 配置管理概览 运行时配置 Hive, Map-Reduce 与本地模式 错误日志 DDL 操作 元数据存储 DML 操作 SQL 操作 查询示例 SELECTS 和 FILTERS GROUP BY JOIN MULTITABLE INSERT STREAMING Simple Example Use Cases MovieLens User Ratin

官方文档 恢复备份指南三 Recovery Manager Architecture

本节讨论以下问题: About the RMAN Environment                        关于RMAN环境 RMAN Command-Line Client                            RMAN命令行 RMAN Channels                                                      RMAN通道 RMAN Repository                                

【Docker官方文档】理解Docker

本文来自Docker的官方文档,详细介绍了Docker的体系结构.重要概念.内部工作机理等内容,推荐不了解Docker内部原理的同学阅读. 什么是Docker? Docker是一个用于开发.交付和运行应用的开放平台,Docker设计用来更快的交付你的应用程序. Docker可以将你的应用程序和基础设施层隔离,并且还可以将你的基础设施当作程序一样进行管理.Docker可以帮助你更块地打包你代码.测试以及部署,并且也可以减少从编写代码到部署运行代码的周期. Docker将一个轻量级的容器虚拟化平台和

官方文档 恢复备份指南六 Configuring the RMAN Environment: Advanced Topics

RMAN高级设置. 本章内容: Configuring Advanced Channel Options  高级通道选项 Configuring Advanced Backup Options 高级备份选项 Configuring Auxiliary Instance Data File Names 配置辅助实例文件名 Configuring the Snapshot Control File Location 配置控制文件快照 Configuring RMAN for Use with a S

【官方文档】RabbitMQ之AMQP

AMQP 0-9-1 Model Explained About This Guide This guide explains the AMQP 0-9-1 model used by RabbitMQ. The original version was written and kindly contributed by Michael Klishin and edited by Chris Duncan. High-level Overview of AMQP 0-9-1 and the AM

新手小白自学hibernate,官方文档错误,导致的坑爹历程

因为是自学的hibernate,所以我先是上网找了些hibernate的视频来看了几天,再浏览的官方文档,最后才开始动手做实践操作,没想到刚开始就出问题了,我将官方文档上的hibernate.cfg.xml完全copy到项目的src目录下,然后修改数据库连接信息,搭建好log4j.junit,当我满怀希望的开始我的第一个小程序时,才发现我下载的hibernate是4.2.21,而看的视频是hibernate3的视频,视频中创建SessionFactory的方法: SessionFactory s