Skip to content

Commit 2a47714

Browse files
author
Johan De Wit
committed
fix authentication function
1 parent e67f403 commit 2a47714

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

templates/mongoshrc.js.erb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ function rsReconfigSettings(settings){
1919
<% if @auth and @store_creds -%>
2020
function authRequired() {
2121
try {
22-
return db.serverCmdLineOpts().code == 13;
22+
return db.serverCmdLineOpts().ok != 1;
2323
} catch (err) {
24-
return false;
24+
if (err.message.match(/requires authentication/)) {
25+
return true
26+
} else {
27+
throw("Unknown error :" + err)
28+
}
2529
}
2630
}
2731

@@ -31,7 +35,7 @@ if (authRequired()) {
3135
db.getMongo().setReadPref('primaryPreferred')
3236
<%- end -%>
3337
try {
34-
var prev_db = db
38+
var prev_db = db.getName()
3539
db = db.getSiblingDB('admin')
3640
db.auth('<%= @admin_username %>', '<%= @admin_password_unsensitive %>')
3741
db = db.getSiblingDB(prev_db)

0 commit comments

Comments
 (0)