Skip to content

Instantly share code, notes, and snippets.

@jeffjohnson9046
Created June 27, 2019 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffjohnson9046/31cfcd01b768c365587bac86f86e3a90 to your computer and use it in GitHub Desktop.
Save jeffjohnson9046/31cfcd01b768c365587bac86f86e3a90 to your computer and use it in GitHub Desktop.
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