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

Mongo shell startup configuration file .mongorc.js (1)

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Mongo shell startup configuration file .mongorc.js (1)

When started, mongo examines a JavaScript file .mongorc.js in the user's HOME directory. If found, mongo parses the contents of .mongorc.js before displaying the prompt for the first time. If you use shell to execute a JavaScript file or evaluate an expression, either by using the-- eval option on the command line or by specifying a .js file to mongo,mongo will read the .mongorc.js file after JavaScript processing. You can use the-- norc option to block the loading of .mongorc.js.

Modify the DBQuery.shellBatchSize variable

The find () method is the JavaScript method that gets the document or collects it. The find () method returns the cursor of the result; however, in mongo shell, if the returned cursor is not assigned to a variable defined with the varkey, the cursor is automatically repeated 20 times, printing the first 20 lines of the matching query. Mongo shell will prompt Type it to repeat 20 times.

You can set the DBQuery.shellBatchSize property to change the number of repeats from the default 20 to 10:

DBQuery.shellBatchSize = 10

Of course, you can set it directly under mongo shell or put it in the configuration file.

Use custom prompt messages

You can create variables under the command line that modify the contents of the prompt. The prompt variable can hold strings as well as any JavaScript. If the prompt save function returns a string, mongo can display each dynamic prompt information. Look at the following example:

Examples

Create a number of prompts for operations issued with the current session, defining the following variables:

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

The prompt will be similar to the following:

1 > db.collection.find () 2 > show collections 3 >

Examples

Create a mongo command line prompt in the form @ $defines the following variables:

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

The prompt will be similar to the following:

@ $use records switched to db records records@$

Examples

To create a mongo command line prompt that contains the system time and the number of files in the current database, define the following prompt variables:

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

The prompt will be similar to the following:

Uptime:5897 Documents:6 > db.people.save ({name: "James"}); Uptime:5948 Documents:7 >

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