MongoDB - The mongo Shell, Configure the mongo Shell
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了MongoDB - The mongo Shell, Configure the mongo Shell,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3240字,纯文字阅读大概需要5分钟。
内容图文
![MongoDB - The mongo Shell, Configure the mongo Shell](/upload/InfoBanner/zyjiaocheng/473/b8040f9bd0514a3cac433d5d27f7f259.jpg)
> 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
标签:https str erp key string class trie actual target
本文系统来源:http://www.cnblogs.com/huey/p/6120258.html
内容总结
以上是互联网集市为您收集整理的MongoDB - The mongo Shell, Configure the mongo Shell全部内容,希望文章能够帮你解决MongoDB - The mongo Shell, Configure the mongo Shell所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。