I'd like to define a custom Mongo shell command. Given .mongorc.js
is like below:
var dbuc;
(function () {
dbuc = (function () {
return db.getName().toUpperCase();
})();
})();
I'm getting proper upper-cased name for initial database, yet when I switch to other database I'm still getting name of the initial database instead of current one.
> db
test
> dbuc
TEST
> use otherbase
> db
otherbase
> dbuc
TEST
I see .mongorc.js
is run before mongo
runs and that's why dbuc
variable has assigned value of initial database - test. But I rather wonder how to get a name of current database whatever base I turned on.