Kamva / mgm

Mongo Go Models (mgm) is a fast and simple MongoDB ODM for Go (based on official Mongo Go Driver)
Apache License 2.0
754 stars 63 forks source link

Authentication Failure #66

Open adimyth opened 2 years ago

adimyth commented 2 years ago

Describe the bug Authentication error when trying to connect to Mongo. I get the following error when trying to connect to mongo using user credentials -

{
    "error": "connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism \"SCRAM-SHA-1\": (AuthenticationFailed) Authentication failed.",
    "ok": false
}

I am able to login via mongo-shell using the same creds as in the screenshot below. However the ORM throws error -

Screenshot 2022-02-26 at 6 45 08 PM

Note: This is similar to this closed issue.

To Reproduce Steps to reproduce the behavior:

  1. Create a test user with the following creds -
    MONGODB_PORT="27017"
    MONGODB_URL="localhost"
    MONGODB_USERNAME="test"
    MONGODB_PASSWORD="test123"
    MONGODB_DB="todos"
  2. Connect to mongo using the ODM

    package main
    
    import (
        "log"
    
        "github.com/Kamva/mgm/v2"
        "go.mongodb.org/mongo-driver/mongo/options"
    )
    
    func init() {
        err = mgm.SetDefaultConfig(nil, "todos", options.Client().ApplyURI("mongodb://test:test123@localhost:27017"))
        if err != nil {
            log.Fatal("Error setting default config")
            log.Fatal(err)
        }
    }

Expected behavior Connection should not fail when trying to connect via above piece of code

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Additional context Add any other context about the problem here.