相关疑难解决方法(0)

Golang 和 MongoDb 远程访问失败(服务器在 SASL 身份验证步骤返回错误:身份验证失败。)

我正在尝试使用 mgo 库从 Go 连接到远程 MongoDB 数据库(Mongolab),但出现错误panic: server returned error on SASL authentication step: Authentication failed。这是我的代码

package main

import (
    "fmt"
    "gopkg.in/mgo.v2"
    "gopkg.in/mgo.v2/bson"
    "log"
)

type Person struct {
    Name  string
    Phone string
}

func main() {
    session, err := mgo.Dial("mongodb://<dbusername>:<dbpassword>@ds055855.mlab.com:55855")

    if err != nil {
        panic(err)
    }
    defer session.Close()

    // Optional. Switch the session to a monotonic behavior.
    session.SetMode(mgo.Monotonic, true)

    c := session.DB("catalog").C("History")
    err = c.Insert(&Person{"Ale", "+55 53 8116 9639"},
        &Person{"Cla", "+55 53 8402 8510"})
    if err …
Run Code Online (Sandbox Code Playgroud)

authentication remote-access go mongodb mlab

3
推荐指数
1
解决办法
7176
查看次数

标签 统计

authentication ×1

go ×1

mlab ×1

mongodb ×1

remote-access ×1