Answer the question
In order to leave comments, you need to log in
What is the procedure for creating a user for remote access to mongodb?
I tried in different ways but it doesn't work: I
created a user in the admin database with the rights "userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase":
use admin
db.createUser({ user: "admin" , pwd: "mypass", roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"]})
use mydb
mongo 127.0.0.1 --port 27017 -u "admin" --authenticationDatabase "mydb"
MongoDB shell version v4.0.2
Enter password:
connecting to: mongodb://127.0.0.1:27017/test
MongoDB server version: 4.0.2
2019-03-18T11:41:55.681+0200 E QUERY [js] Error: Authentication failed. :
[email protected]/mongo/shell/db.js:1685:20
@(auth):6:1
@(auth):1:2
exception: login failed
mongo 127.0.0.1 --port 27017 -u "admin" --authenticationDatabase "admin"
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
net:
port: 27017
bindIp: 127.0.0.1
Answer the question
In order to leave comments, you need to log in
Look at the documentation, especially point 6: https://docs.mongodb.com/manual/tutorial/enable-au...
Please note that you create the admin user in the admin database with the userAdminAnyDatabase role, that is, he is the administrator of all databases on this server. The key "--authenticationDatabase" indicates that you are authorized through the database in which the user was created. When you try to fulfill
mongo 127.0.0.1 --port 27017 -u "admin" --authenticationDatabase "mydb"
mongo cannot find the specified user in mydb.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question