Skip to content

Commit e811dc7

Browse files
author
Johan De Wit
committed
[authentication] fix authentication function
1 parent a4f06ba commit e811dc7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

templates/mongoshrc.js.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ 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) {
2424
if (err.message.match(/requires authentication/) || err.message.match(/not authorized on admin/)) {
2525
return true
@@ -35,7 +35,7 @@ if (authRequired()) {
3535
db.getMongo().setReadPref('primaryPreferred')
3636
<%- end -%>
3737
try {
38-
var prev_db = db
38+
var prev_db = db.getName()
3939
db = db.getSiblingDB('admin')
4040
db.auth('<%= @admin_username %>', '<%= @admin_password_unsensitive %>')
4141
db = db.getSiblingDB(prev_db)

0 commit comments

Comments
 (0)