I want to join mongodb by node.js
localhost with authenticated user
I made this steps as follow
1- run mongo from bin
2- use ais_mlm db
3-createUser admin with password admin
4- edit config file to authorization enable
5- restart mongodb server from task manager
6- go to node.js project folder and run nodemon
show error cannot connect to mongodb
here is string url for this
DATA = “mongodb://admin:admin@localhost:27017/ais_mlm?authSource=admin”
I tried both options to connect to DB but it threw an error:
TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:372:5)
at URL.onParseError (node:internal/url:553:9)
at new URL (node:internal/url:629:5)
at isAtlas (G:\My Projects\express_js\task_manager\node_modules\mongoose\lib\helpers\topology\isAtlas.js:17:17)
at MongooseServerSelectionError.assimilateError (G:\My Projects\express_js\task_manager\node_modules\mongoose\lib\error\serverSelection.js:35:35)
at G:\My Projects\express_js\task_manager\node_modules\mongoose\lib\connection.js:813:36
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
input: ‘123:27017’,
code: ‘ERR_INVALID_URL’
}
Your password root@123 completely screw up the URI parser because the @ is used as a separator between the credentials and the host part. So it tries with the password root and the host 123@localhost.