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:
- Mongovue is unable to create collections and log in with user name and password
- Error occurred when using java to connect mongodb: command failed with error 18 (authentication failed): “authentication failed.”
- mongodb not authorized on admin to execute command [version 3.2.18]
- How to Solve MongoDB Error: Authentication failed.
- mongodb:E QUERY [thread1] SyntaxError: missing ; before statement @(shell):1:4
- [Solved] Mongodb startup error: about to fork child process, waiting until server is ready for connections.
- Unable to start mongod after installing mongodb in Ubuntu
- MongoDB Startup Error: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
- [Solved] Mongodb Error: NETWORK [thread1] Failed to connect to 127.0.0.1:27017
- Solve Error: MissingSchemaError: Schema hasn’t been registered for model “YourModel”.