Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

5. Configure the mongo command line

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

5. Configure the mongo command line

The latest content will be updated at the origin server. To reprint, please keep the original link: http://dashidan.com/article/mongodb/index.html

① .mongorc.js file

When MongoDB starts, mongo checks the user's HOME directory for a JavaScript file named .mongorc.js. If the file mongo is found, the contents of the .mongorc.js file will be interpreted before running the command prompt for the first time.

When starting, mongo checks the user's HOME directory for a JavaScript file named .mongorc.js. If found, mongo interprets the content of .mongorc.js before displaying the prompt for the first time.

When you execute a JavaScript file or expression with the-- eval parameter on the mongo command line or specify a .js file, mongo will read the .mongorc.js file after executing the command.

You can disable reading the .mongorc.js file with the-- norc parameter.

This file is not available by default. You need to create one by yourself.

② Custom display Line count

You can enter the following code on the mongo command line to display the number of lines of code:

CmdCount = 1 prompt = function () {return (cmdCount++) + ">";}

What the command line looks like:

The variable name of 1 > 2 > 3 > `roomt` cannot be changed. The change is invalid.

The ③ mongo command line displays the data name and hostname

Host = db.serverStatus (). Host;prompt = function () {return db+ "@" + host+ "$";}

The command prompt displays:

Test@myHost1 $

④ mongo Command Line Custom display Runtime and number of documents

Prompt = function () {return "Uptime:" + db.serverStatus () .uptime+ "Documents:" + db.stats () .run ">";} run time in seconds.

The content of the code may be modified. This is decided by the JavaScript compiler. For example, it is possible to convert `1 + 1` to `2` or delete comments.

⑤ uses an external editor

I tried it, and it works in linux, but not in windows.

The mongo command prompt explains the code edited by the external editor

The content of the code may be modified. This is decided by the JavaScript compiler. For example, it is possible to convert `1 + 1` to `2` or delete comments.

Export EDITOR=vimmongo

On the mongo command line, you can activate the external editor by typing edit or edit.

1. Define the method function myFunction () {} 2. Activate an external editor to edit the method edit myFunction

The vim editor is activated in the linux system. After editing, save and exit vim.

3. View the method myFunction in the mongo command line

Will show

Function myFunction () {print ("This was edited");} mongo command prompt interprets the code edited by the external editor

The content of the code may be modified. This is decided by the JavaScript compiler. For example, it is possible to convert `1 + 1` to `2` or delete comments.

⑥ modifies the number of lines displayed at the mongo command prompt

The db.collection.find () method returns a result pointer. This method returns the first 20 pieces of data by default. Enter it or continue to display 20 entries.

You can modify the number of documents by setting DBQuery.shellBatchSize.

For example: display 10 lines at a time.

DBQuery.shellBatchSize = 10; modify at the mongo command prompt to affect only the current window display.

⑦ reference articles

Official website article

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report