Customize the Prompt
Modify the content of the prompt by setting the variablepromptin theMONGOshell. Thepromptvariable can hold strings as well as JavaScript code. Ifpromptholds a function that returns a string, theMONGOcan 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 theMONGOs Hell.
Customize Prompt to Display number of Operations
For example,to Create aMONGOshell prompt with the number of operations issued in the current session, define th E following variables in theMONGOShell:
> 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 aMONGOshell prompt in the form of<database>@, define the following V Ariables:
3> prompt = "> "
> host = db.serverStatus().host;
huey
> prompt = function() {
... return db+"@"+host+"$ ";
... }
function () {
return db+"@"+host+"$ ";
}
The prompt would then resemble the following:
[email protected]$
Customize Prompt to Display up time and Document Count
To create aMONGOshell Prompt This contains the system up time and the number of documents in the Curre NT database, define the followingpromptvariable in theMONGOShell:
[email protected]$ 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 a External Editor in theMONGOShell
You can use your own editor on theMONGOshell by setting the editorenvironment variable before starting theMONGOshell.
Export Editor=vimmongo
Once in theMONGOshell, you can edit with the specified editor by typing edit <variable> oredit <function>, as in the following example:
- Define a function myfunction :
function MyFunction () {}
- edit the function using your editor:
edit myFunction
The command sh Ould Open THE&NBSP;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 is the changes from your saved edit:
function myFunction() {
print("This was edited");
}
Note: AsMONGOShell interprets code edited in a external editor, it may modify code in functions, depending on the Ja Vascript compiler. ForMONGOcould convertto2or remove comments. The actual changes affect only the appearance of the code and would vary based on the version of JavaScript used but would n OT affect the semantics of the code.
Change theMONGOShell Batch Size
The db.collection.find () method is The JavaScript method to retrieve documents from A collection. THE&NBSP;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-to-the-print up-to-the-first documents that match the query. THE&NBSP;mongo shell would prompt
You can set the "dbquery.shellbatchsizeattribute to" the number of documents from the default valueofas in the following example which sets it to:
Dbquery.shellbatchsize = 10;
Mongodb-the MONGO Shell, Configure the MONGO shell