MongoDB - The mongo Shell, 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 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 .mongorc.js file to set the prompt each time you start up the mongo 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 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:
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 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:
- Define a function myFunction:
function myFunction () { } - 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.
- 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.
Change the mongo Shell Batch Size
The db.collection.find() method is the JavaScript method to retrieve documents from a collection. The db.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 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;
MongoDB - The mongo Shell, Configure the mongo Shell的更多相关文章
- MongoDB的安装,mongod和mongo的区别
一. mongoDB安装路径 安装路径(最新4.0.11):https://www.mongodb.com/download-center/community?jmp=nav 建议另外找路径下载,外网 ...
- MongoDB学习笔记:文档Crud Shell
MongoDB学习笔记:文档Crud Shell 文档插入 一.插入语法 db.collection.insertOne() 将单个文档插入到集合中.db.collection.insertMan ...
- 1.Configure the mongo Shell-官方文档摘录
Customize the Prompt 自定义提示 You may modify the content of the prompt by setting the variable prompt i ...
- MONGODB(三)——Java操作Mongo
相比于java调用MySqlApI来操作数据库,调用Mongo要简洁容易的多.通过一个简单的样例,很容易地就可以上手 一.导入Jar包 添加Monog支持Java的jar包,这里使用的是2.9.3 & ...
- 交互式shell和非交互式shell、登录shell和非登录shell的区别
交互式shell和非交互式shell.登录shell和非登录shell的区别.首先,这是两个不同的维度来划分的,一个是是否交互式,另一个是是否登录. 交互式shell和非交互式shell(intera ...
- linux中的shell脚本编程---初识shell
Shell是用户与Linux或Unix内核通信的工具,shell编程指的并不是编写这个工具,而是指利用现有的shell工具进行编程,写出来的程序是轻量级的脚本,我们叫做shell脚本. Shell的语 ...
- Ubuntu下把缺省的dash shell修改为bash shell
Ubuntu下缺省使用的是shell是dash,而不是bash.从/bin/sh软连接的指向可以看出这点. dash shell 虽然比bash shell更轻便,但是它并不支持所有的语法,运行she ...
- Shell编程-11-子Shell和Shell嵌套
目录 什么是子Shell 子Shell产生的途径 Shell脚本调用模式 什么是子Shell 子Shell的概念其实是贯穿整个Shell的,如果想要更好的理解和写Shell脚本则必须要了解子S ...
- [shell]shell 中| && || () {} 用法以及shell的逻辑与或非
转自:https://www.jianshu.com/p/617c1ee1e46e | 运算符 管道符号,是unix一个很强大的功能,符号为一条竖线:"|".用法: command ...
随机推荐
- javascript第三方组件
一.一个javascript文件上传组件.转载:http://www.cnblogs.com/fumj/archive/2012/12/07/2806673.html http://fineuploa ...
- linux集群管理<转>
云在根本上是由硬件和软件组成的,这些组件需要经常细心地维护.出现故障的硬件需要修理或更换:软件需要应用补丁.更新和升级:必须根据需求和潜在的安全威胁提前配置系统.应用程序开发人员可能觉得计算云很方便. ...
- 微价值:专訪《甜心爱消除》个人开发人员Lee,日入千元!
[导语]我们希望能够对一些个人开发人员进行专訪,这样大家更能显得接地气,看看人家做什么,怎么坚持.<甜心爱消除>作者Lee是三群的兄弟,也关注微价值.微价值的文章还是能够的,得到一些业内大 ...
- 数据对象ajax学习篇9
题记:写这篇博客要主是加深自己对数据对象的认识和总结实现算法时的一些验经和训教,如果有错误请指出,万分感谢. 对ajax工作道理: 下面这段是来自一个网友的blog: Ajax的道理简单来说通过Xml ...
- HDU 5584 LCM Walk 数学
LCM Walk Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5584 ...
- Codeforces Gym 100187E E. Two Labyrinths bfs
E. Two Labyrinths Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/prob ...
- Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 贪心/二分
C. GukiZ hates Boxes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...
- iOS开发——开发必备OC篇&UITableView设置界面完整封装(三)
UITableView设置界面完整封装(三) 简单MVC实现UITableView设置界面之界面跳转 创建一个需要调整的对应的控制器 在需要调整的类型模型中创建对应的属性用来实现调整类型控制器的设置 ...
- iOS开发——实用OC篇&多种定时器详细介绍
多种定时器详细介绍 在软件开发过程中,我们常常需要在某个时间后执行某个方法,或者是按照某个周期一直执行某个方法.在这个时候,我们就需要用到定时器. 然而,在iOS中有很多方法完成以上的任务,到底有 ...
- CSS3实现自定义Checkbox和Radiobox
我们知道浏览器自带的Checkbox复选框不怎么美观(这或许是我们看习惯了的缘故),而且复选框在不同的浏览器上显示的样式又有很大的差异,由于目前越来越多的人开始接受支持CSS3的现代浏览器,所以今天就 ...