Answer the question
In order to leave comments, you need to log in
Missing MongoDB databases?
Good day! I tried to set up access to the database by login / password. I created a user under which I could not log in, later it "did not exist" in the admin database. After that, all the databases created by me disappeared ...
Does anyone know what happened in this situation?
Answer the question
In order to leave comments, you need to log in
If you do as you described - authorization is successful. Probably, somewhere in the process of setting up or authorization, an error was made - for example, the user was created in the wrong database or something else.
docker volume create testvol
docker run --rm --name test-mongo -v "testvol:/data/db" -d mongo
docker exec -it test-mongo mongo
use testDb;
db.createCollection("testCollection");
use admin;
db.createRole({
role: "Admin",
privileges: [{
resource: {
db: "testDb",
collection: "testCollection"
},
actions: ["anyAction", "internal"]
}],
roles: []
});
db.createUser({
user: "Admin",
pwd: "testpasswd",
roles: ["Admin"]
});
db.adminCommand({"listDatabases":1, "filter": {"name": "testDb"}, "nameOnly": true});
// { "databases" : [ { "name" : "testDb" } ], "ok" : 1 }
docker stop test-mongo
docker run --rm -v "testvol:/data/db" --name test-mongo -d mongo --auth
docker exec -it test-mongo mongo
db.adminCommand({"listDatabases":1, "filter": {"name": "testDb"}, "nameOnly": true});
//{
// "ok" : 0,
// "errmsg" : "command listDatabases requires authentication",
// "code" : 13,
// "codeName" : "Unauthorized"
//}
use admin;
db.auth("Admin", "testpasswd");
// 1
db.adminCommand({"listDatabases":1, "filter": {"name": "testDb"}, "nameOnly": true});
// { "databases" : [ { "name" : "testDb" } ], "ok" : 1 }
docker run --rm -v "testvol:/data/db" --name test-mongo -d mongo
docker exec -it test-mongo mongo
use admin;
// switched to db admin
db.getUsers();
// [{ "_id" : "admin.Admin", ...
db.dropUser("Admin");
// true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question