User doesn't get authenticated properly (MongoDB - buildConnectionUrl)
See original GitHub issueUsed MongoDB Version: 3.4 Problem: The user doesn’t get authenticated properly.
File: typeorm/driver/mongodb/MongoDriver.js
MongoDriver.prototype.buildConnectionUrl = function () {
if (this.options.url)
return this.options.url;
return "mongodb://" + (this.options.host || "127.0.0.1") + ":" + (this.options.port || "27017") + "/" + this.options.database;
};
The created URL seems to be wrong, the correct version should be
(this.options.username != null) ? "mongodb://" + this.options.username + ":" + this.options.password + "@" + (this.options.host || "127.0.0.1") + ":" + (this.options.port || "27017") + "/" + this.options.database : "mongodb://" + this.options.username + ":" + this.options.password + "@" + (this.options.host || "127.0.0.1") + ":" + (this.options.port || "27017") + "/" + this.options.database;
(In case the username is null the “authentication part” in the URL won’t get added)
Reference: https://docs.mongodb.com/manual/reference/connection-string/
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Can't connect to mongod with the newly created user - M103
I connected to mongo and created a new user, but i can't access with the --auth command and -u -p from my user:...
Read more >MongoDB 3.2 authentication failed
Solution: Just try to create your users (without authentication enabled initially on MongoDB) and do it directly on the console of your DB ......
Read more >How to specify authentication database and target ...
I have tried this uri but it doesn't work. Because it tries to use test as the authentication database which is not correct....
Read more >Connecting to MongoDB databases | Prisma's Data Guide
Once you have a MongoDB server available, one of the first and most common actions you'll need to take is to connect to...
Read more >How To Secure MongoDB on Ubuntu 18.04
MongoDB doesn't have authentication enabled by default, meaning that any user with access to the server where the database is installed can ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For me authentication is working with Mongo 3.4, maybe try to add to the options
“authSource”: “admin”
I have checked with a new mongodb instance and a basic example and it worked (using @webstrap’s suggestion) . Please reopen if problem still persists