1.Configure the mongo Shell-官方文档摘录
2017-07-18 08:46
531 查看
Customize the Prompt 自定义提示
You may modify the content of the promptby setting the variablepromptin the
mongoshell. The
promptvariable can hold strings as well as JavaScript code. If
promptholds a function that returns a string,
mongocan display dynamic information in each prompt.
You can add the logic for the promptin the .mongorc.js file to set the prompteach time you start up the
mongoshell.
大概的意思:你可以通过修改mongorc.js这个文件来让你的终端提示符变得不太一样
注意:
# vim /root/.mongorc.js
如果使用yum 装的,这个文件在/root/目录下
Customize Prompt to Display Number of Operations
For example,to create amongoshell promptwith the number of operations issued in the current session, define the following variables in the
mongoshell:
cmdCount = 1;
prompt= function() {
return (cmdCount++) + "> ";
}
The promptwould then resemble the following:
1> 2> 3>
Customize Prompt to Display Database and Hostname
To create amongoshell promptin the form of
<database>@<hostname>$, define the following variables:
host = db.serverStatus().host;
prompt= function() {
return db+"@"+host+"$ ";
}
The promptwould then resemble the following:
test@myHost1$
Customize Prompt to Display Up Time and Document Count
To create amongoshell promptthat contains the system up time and the number of documents in the current database, define the following
promptvariable in the
mongoshell:
prompt= function() {
return "Uptime:"+db.serverStatus().uptime+" Documents:"+db.stats().objects+" > ";
}
The promptwould then resemble the following:
Uptime:5897 Documents:6 >
Use an External Editor in the mongo
Shell
You can use your own editor in the mongoshell by setting the
EDITORenvironment variable before starting the
mongoshell.
export EDITOR=vim mongo
Once in the
mongoshell, 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
vimedit session. When finished with the edits, save and exit
vimedit session.
In the
mongoshell, type
myFunctionto see the function definition:
myFunction
The result should be the changes from your saved edit:
function myFunction() { print("This was edited"); }
NOTE
As
mongoshell interprets code edited in an external editor, it may modify code in functions, depending on the JavaScript compiler. For
mongomay convert
1+1to
2or 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. The
db.collection.find()method returns a cursor to the results; however, in the
mongoshell, if the returned cursor is not assigned to a variable using the
varkeyword, then the cursor is automatically iterated up to 20 times to print up to the first 20 documents that match the query. The
mongoshell will prompt
Typeitto iterate another 20 times.
You can set the
DBQuery.shellBatchSizeattribute 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来设置
相关文章推荐
- 14.Iterate a Cursor in the mongo Shell-官方文档摘录
- 2.Access the mongo Shell Help-官方文档摘录
- 3.Write Scripts for the mongo Shell-官方文档摘录
- 4.Data Types in the mongo Shell-官方文档摘录
- MongoDB - The mongo Shell, Configure the mongo Shell
- Python 官方文档学习笔记 topic2 Using the Python Interpreter
- 简读The Swift Programming Language官方文档--函数
- Rhyme/Spring5.0.2.RELEASE官方英文文档学习笔记(1) Introduction to the Spring IoC container and beans
- Cocos Creator 加载和切换场景(官方文档摘录)
- Cocos Creator 使用计时器(官方文档摘录)
- The Swift Programming Language 英文原版官方文档下载
- mongo官方文档阅读笔记---mongo的限制
- hadoop分布式文件系统中的shell命令(转自官方文档)
- Influxdb-官方文档摘录
- Influxdb-官方文档摘录
- CritterAI官方文档翻译【The Input Build】
- 11.Query an Array of Embedded Documents-官方文档摘录
- Android官方文档翻译 十一 2.4Overlaying the Action Bar
- Introduction to the Service Provider Interfaces--官方文档
- 简读The Swift Programming Language官方文档--控制流