Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A prompt for the mongo shell that displays the user you're logged in as and the database you're pointed at.
/**
Set the mongo shell prompt to display [user name]@[database name]. If the user or database name cannot
be captured, then display "<none>" instead.
*/
var prompt = function() {
var user = db.runCommand({connectionStatus : 1}).authInfo.authenticatedUsers[0].user || "<none>";
var dbLabel = db.getName() || "<none>";
return user + "@" + dbLabel + ">";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.