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

The prompt would then resemble the following: 

<database>@<hostname>$ use records switched to db records records@<hostname>$ 

## Example 

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: 

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

The prompt would then resemble the following: 

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

## Use an External Editor in the mongo Shell 

New in version 2.2. 

In the mongo shell you can use the edit operation to edit a function or variable in an external editor. The edit operation uses the value of your environments EDITOR variable. 

At your system prompt you can define the EDITOR variable and start mongo with the following two operations: 

export EDITOR=vim mongo 

Then, consider the following example shell session: 

MongoDB shell version: 2.2.0 > function f() {} > edit f > f function f() { print("this really works"); } > f() this really works > o = {} { } > edit o > o { "soDoes" : "this" } > 

Note: As mongo shell interprets code edited in an external editor, it may modify code in functions, depending on 

