I have a mlab MongoDB database called storyfactory.
This database has a collection called test, which has a user called Standard with a Password.
I'm trying to connect to the database with this Driver.
This is the code:
package main
import (
"context"
"fmt"
"log"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func main() {
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://<Standard>:<Password>@ds127101.mlab.com:27101/storyfactory"))
if err != nil {
log.Fatal(err)
}
collection := client.Database("storyfactory").Collection("test")
ctx, _ = context.WithTimeout(context.Background(), 5*time.Second)
res, err := collection.InsertOne(ctx, bson.M{"name": "pi", "value": 3.14159})
if err != nil {
log.Fatal(err)
}
fmt.Println(res.InsertedID)
}
If I try to run this code, I get following output:
2019/03/12 18:09:04 auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
exit status 1
I'm 100% sure that the Password is correct.
Thanks for your help!