How to connect mongodb 3.0 in golang

When I upgrade my mongodb server to version 3.0 of 2.6 , it cannot connect to golang use mgo.

I add 'authMechanism=SCRAM-SHA-1' to the connection string and still cannot connect to the server. The error I get is SASL support not enabled during build (-tags sasl)

+5
source share
2 answers

I had a similar problem. The meaning that I found around the network, which should be included in the package "labix.org/v2/mgo", despite the fact that on the official website http://labix.org/mgo (while reading) it has more new and updated information that points to at least my gopkg.in/mgo.v2 package.

Hope this helps, as I got to the same steps as you, but then changed the link to the package. This code worked in my case:

  package main import ( "fmt" "time" "gopkg.in/mgo.v2" ) //const MongoDb details const ( hosts = "ds026491.mongolab.com:26491" database = "messagingdb" username = "admin" password = "youPassword" collection = "messages" ) func main() { info := &mgo.DialInfo{ Addrs: []string{hosts}, Timeout: 60 * time.Second, Database: database, Username: username, Password: password, } session, err1 := mgo.DialWithInfo(info) if err1 != nil { panic(err1) } col := session.DB(database).C(collection) count, err2 := col.Count() if err2 != nil { panic(err2) } fmt.Println(fmt.Sprintf("Messages count: %d", count)) } 

It is also on github

+1
source

change server configuration:

> var schema = db.system.version.findOne({"_id" : "authSchema"})
> schema.currentVersion = 3
> db.system.version.save(schema)

https://jira.mongodb.org/browse/SERVER-17459

0
source

All Articles