Configure themongo
Shell
You may modify the content of the prompt by setting the variableprompt
in theshell. Theprompt
variable can hold strings as well as JavaScript code. Ifprompt
holds a function that returns a string,mongo
can display dynamic information in each prompt.
You can add the logic for the prompt in thefile to set the prompt each time you start up themongo
shell.
For example,to create ashell prompt with the number of operations issued in the current session, define the following variables in themongo
shell:
The prompt would then resemble the following:
1
>
2
>
3
>
To create ashell prompt in the form of<database>@<hostname>$
, define the following variables:
host
=
db
.
serverStatus
().
host
;
prompt
function
()
{
return
+
"@"
+
host
+
"$ "
;
}
test@myHost1$
To create amongo
shell prompt that contains the system up time_and_the number of documents in the current database, define the followingprompt
variable in theshell:
The prompt would then resemble the following:
Uptime
:
5897
Documents
:
6
>
You can use your own editor in themongo
shell by setting theenvironment variable_before_starting themongo
shell.
export
EDITOR
=
mongo
Once in theshell, you can edit with the specified editor by typingedit<variable>
oredit<function>
, as in the following example:
Define a function
myFunction
:function
myFunction
()
}
-
The command should open the
vim
edit session. When finished with the edits, save and exitvim
edit session. In the
mongo
shell, typemyFunction
to see the function definition:myFunction
The result should be the changes from your saved edit:
function
myFunction
()
{
print
(
"This was edited"
);
}
NOTE
Asshell interprets code edited in an external editor, it may modify code in functions, depending on the JavaScript compiler. Formongo
may convert1+1
to2
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.
You can set theDBQuery.shellBatchSize
attribute to change the number of documents from the default value of20
, as in the following example which sets it to10
:
DBQuery
.
shellBatchSize
=
10