0

I am trying to run some shell commands in mongo which is inside docker container.

docker exec -it mongodb_mock  bash

It opens the mongo shell. but when I run any command in this it gives authentication error:

    > show dbs
2018-08-28T10:12:12.755+0000 E QUERY    [thread1] Error: listDatabases failed:{
    "ok" : 0,
    "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
    "code" : 13,
    "codeName" : "Unauthorized"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
shellHelper.show@src/mongo/shell/utils.js:781:19
shellHelper@src/mongo/shell/utils.js:671:15
@(shellhelp2):1:1

Please help.

EDIT: This db is created through mongoose/express, from another container.

1
  • you ran mongod deamon with --auth option so you should authorize with admin user then only you can perform any query Commented Aug 28, 2018 at 10:25

1 Answer 1

2

first you need to authorize db with user, below is example command

use admin;
db.auth('admin','password');

then your able to run all querys. or start mongod without --auth parameter so you no need user authentication.

Sign up to request clarification or add additional context in comments.

2 Comments

> db.auth("admin", "admin") Error: Authentication failed.
please check username and password are correct? and replace double quotes with single quote, i have added another command

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.