question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

User doesn't get authenticated properly (MongoDB - buildConnectionUrl)

See original GitHub issue

Used 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:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

22reactions
webstrapcommented, Jan 7, 2018

For me authentication is working with Mongo 3.4, maybe try to add to the options

“authSource”: “admin”

0reactions
championswimmercommented, Sep 27, 2018

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found