Skip to content

Instantly share code, notes, and snippets.

@fatmcgav
Created April 17, 2015 13:32
Show Gist options
  • Save fatmcgav/e21f1a32399a782152ba to your computer and use it in GitHub Desktop.
Save fatmcgav/e21f1a32399a782152ba to your computer and use it in GitHub Desktop.
Mongo-shell exit status when 'auth failed'
# mongo admin --quiet --host 127.0.0.1:27017 --eval "load('/root/.mongorc.js'); db.version()"; echo $?
2.6.9
0
# mongo admin1 --quiet --host 127.0.0.1:27017 --eval "load('/root/.mongorc.js'); printjson(db.system.users.find().toArray())"; echo $?
Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 }
2015-04-17T14:23:16.317+0100 error: { "$err" : "not authorized for query on admin1.system.users", "code" : 13 } at src/mongo/shell/query.js:131
252
# mongo appdb --quiet --eval "load('/root/.mongorc.js'); db.runCommand({\"createUser\": \"app-user\",\"pwd\": \"baaa8ad52b17ec7fbe0a76893e388061\",\"customData\": {\"createdBy\": \"Puppet Mongodb_user['User app-user on db appdb']\"},\"roles\": [\"dbAdmin\"],\"digestPassword\": false})"; echo $?
Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 }
[object Object]
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment