Golang和MongoDB远程访问失败(服务器上的SASL身份验证步骤返回的错误:验证失败。) [英] Golang and MongoDb remote access fail (server returned error on SASL authentication step: Authentication failed.)

查看:8060
本文介绍了Golang和MongoDB远程访问失败(服务器上的SASL身份验证步骤返回的错误:验证失败。)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从围棋与氧化镁库连接到远程数据库的MongoDB(Mongolab),但得到错误的恐慌:在SASL身份验证步骤服务器返回错误:验证失败。这里是我的code

I am trying to connect to remote MongoDB database (Mongolab) from Go with mgo library but getting error panic: server returned error on SASL authentication step: Authentication failed. Here is my code

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 != nil {
        log.Fatal(err)
    }

    result := Person{}
    err = c.Find(bson.M{"name": "Ale"}).One(&result)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("Phone:", result.Phone)
}

我该如何解决这个问题?当然不是我的code星的我写我的登录名和密码。

How can I fix this? And of course instead of stars in my code i write my login and password.

推荐答案

请检查您是否添加了用户为你的Mongolab数据库实例(的 https://mongolab.com/databases/catalog#users 的情况下,如果你的数据库名称是目录),因为默认情况下,你的用户列表为空(帐号用户名/密码!=数据库用户名/密码)。

Please check if you have added users for your Mongolab database instance (https://mongolab.com/databases/catalog#users in case if your DB name is catalog) because by default your users list is empty (account user/password != database user/password).

另外补充 /&LT;数据库名称&GT; 来连接字符串的结尾 - 的mongodb:// *******:* ****** @ ds045795.mongolab.com:45795/databasename

Also add /<databasename> to the end of your connection string - mongodb://*******:*******@ds045795.mongolab.com:45795/databasename.

这篇关于Golang和MongoDB远程访问失败(服务器上的SASL身份验证步骤返回的错误:验证失败。)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆