Skip to content

Instantly share code, notes, and snippets.

@Ulv
Forked from david-torres/db_exists.js
Last active August 29, 2015 14:08
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 Ulv/b53045cff61b69be91fe to your computer and use it in GitHub Desktop.
Save Ulv/b53045cff61b69be91fe to your computer and use it in GitHub Desktop.
function db_exists(db_name) {
db = db.getSiblingDB('admin');
db.runCommand('listDatabases').databases.forEach(function(db_entry){
if (db_entry.name == db_name) {
// quit with exit code zero if we found our db
quit(0);
}
});
// quit with exit code 1 if db was not found
quit(1);
}
db_exists('MY_DATABASE');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment