Mongodb access control is not enabled for the database

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

Reprinted: https://blog.csdn.net/q1056843325/article/details/70941697

There are some problems with mongodb today

There are warnings when establishing a database connection

The reason for this warning is that the new version of mongdb must be verified in order to create a secure database
later, the answer was found on the Internet

The solution is as follows:

Create administrator

Use admin
dB. CREATEUSER (
{
User: “useradmin”,// user name
PWD: “123”,// password
roles: [{role: “useradminanydatabase”, DB: “admin”}]// permissions
}
)

Restart mongodb server

mongod –auth –port 27017 –dbpath < Association path & gt
1
(the default port is 27017, which can not be specified)

Finally, the terminal outputs “[initandlisten] waiting for connections on port 27017”,
the startup is completed

Connect and authenticate

Mongo — port 27017 – U “useradmin” — P “123” — authenticationdatabase “admin”
1
add additional users

Use test
dB. CREATEUSER (
{
User: “tester”,
PWD: “123”,
roles: [{role: “readwrite”, DB: “test”},
{role: “read”, DB: “reporting”}]
}
)
Mongo — port 27017 – U “mytester” – P “xyz123” – authentication database “test”

mongodb has been updated, Using mongoose can not simply establish a connection,
necessary parameters must be added

var mongoose = require(‘mongoose’);
var db = mongoose.createConnection(‘localhost’, ‘test’, 27017, {user: ‘tester’, pass: ‘123’});

Similar Posts: