-
-
Save Ulv/b53045cff61b69be91fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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