zhaoyi0113 / mongodb-runner

Other
18 stars 5 forks source link

Failed to connect MongoDB #6

Closed MiruhiMiruhi closed 6 years ago

MiruhiMiruhi commented 6 years ago

Can't connect even with the correct password

zhaoyi0113 commented 6 years ago

The password is set at runtime. When you connect to a mongo instance and set the username on the settings, there should be a prompt input asking for password. You can input the password there for connection. Below is an example of configuration

"connection": {
            "activeOnStartUp": true,
            "url": "mongodb://hostname:port/databaseName",
            "user": "admin"
        }

Please let me know if it doesn't work for you.

zhaoyi0113 commented 6 years ago

Fixed in the latest version

ThomasGHenry commented 5 years ago

+1

zhaoyi0113 commented 5 years ago

@ThomasGHenry Could you give more info on this issue? What is your configuration and what error did you get?

ThomasGHenry commented 5 years ago

Thanks!

I know the DEV config probably wouldn't work, but I modeled the LIVE one on the comments here, and it still doesn't work. The same config works on my live server though, as well as via compass.

// ... other settings in settings.json ...
  "mongoRunner": {
    "connections": [
      {
        "name": "LIVE",
        "url": "mongodb://blah.mlab.com:port1/blah",
        "user": "blah_user"
      },
      {
        "name": "DEV",
        "url": "mongodb://blah_user:password@blah.mongodb.net:port2,blah.mongodb.net:port2,blah.mongodb.net:port2/test?ssl=true&replicaSet=blah-shard-0&authSource=admin&retryWrites=true"
      }
    ]
  },
// ... other settings in settings.json ...

Thanks, again!

ThomasGHenry commented 5 years ago
  "mongoRunner": {
    "connection": {
      "name": "LIVE",
      "url": "mongodb://blah.mlab.com:port1/blah",
      "user": "blah_user"
    }
  },

Same thing. It prompts for the password when I try to connect and the dialog shows the correct user and host, but then the connection fails. I didn't see logs any obvious place. Are there any?

zhaoyi0113 commented 5 years ago

What is the version of your mongodb server?

And what do you mean by The same config works on my live server though? Does the LIVE config work or not?

ThomasGHenry commented 5 years ago

Sorry. I see the ambiguity in how I explained that. I mean the attributes that this config represents work elsewhere. My server (ExpressJS) can connect to that mongo host with the port, user, password, etc that I'm using in this mongo runner config. I can also connect with those parameters from the mongo GUI (compass, I think it's called). I'm not at the computer right now, but I'll look into the mongo version ASAP. It's whatever you get by default on mlab. Thanks again!

EDIT: Answers. The LIVE config doesn't work (per above). I believe the MongoDB version is 3.6 because that's the mlab default. I'll confirm later today.

ThomasGHenry commented 5 years ago

mongod version: 3.6.6 (MMAPv1)

zhaoyi0113 commented 5 years ago

I created a mongodb 3.6.6. and use below command to create an user.

db.createUser(
  {
    user: "reportsUser",
    pwd: "12345678",
    roles: [
       { role: "read", db: "reporting" },
       { role: "read", db: "products" },
       { role: "read", db: "sales" },
       { role: "readWrite", db: "accounts" }
    ]
  }
)

And I am able to connect to the server by below configuration.

"mongoRunner": {
        "connections": [
            {
                "name": "conn1",
                "url": "mongodb://localhost:27017/test",
                "user": "reportsUser"
            }
        ]
    },

Are you able to connect to the server via mongo shell with this url pattern? $ mongo mongodb://reportsUser:12345678@localhost:27017/test.

ThomasGHenry commented 5 years ago

In reality url": "mongodb://blah.mlab.com:port1/blah" ended up being more like url": "mongodb://blah.mlab.com:port1/blahX",. Please accept my shame and gratitude.

🤦‍♂️ Thanks!