2017-06-15 32 views
-1

我嘗試連接在bluemix與golang程序連接構成mongodb,但我得到不受支持的連接url選項ssl。在這裏,我給了從控制檯獲得的mongodb連接字符串。如何連接遠程主機需要連接語法?如何連接與golang構成mongodb

session, err := mgo.Dial("mongodb://****:****@aws-us-east-1-portal.26.dblayer.com:20258/admin?ssl=true") 
    if err != nil { 
     panic(err) 
    } 
    defer session.Close() 

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

    c := session.DB("test").C("people") 
    err = c.Insert(&Person{"Ale", "+55 53 8116 9639"}, 
     &Person{"Cla", "+55 53 8402 8510"}) 
    if err != nil { 
     log.Fatal(err) 
    } 

錯誤:

panic: unsupported connection URL option: ssl=true 

goroutine 1 [running]: 
panic(0x2130a0, 0xc82000a840) 
    /usr/local/go/src/runtime/panic.go:481 +0x3e6 
main.main() 
    /Users/vit/gocode/src/mongmix/mmix.go:19 +0x9b 
exit status 2 
+3

對於錯誤消息「不支持的連接URL選項:ssl = true」究竟有什麼不清楚?看看文檔中關於連接選項的說明可能是有益的:https://godoc.org/labix.org/v2/mgo#Dial – Volker

回答

0

IBM Bluemix撰寫MongoDB的有一個可用的在線文檔瀏覽:https://console.bluemix.net/docs/services/ComposeForMongoDB/index.html#getting-started-with-compose-for-mongodb

步驟有關連接到您的撰寫蒙戈DB 2會談。在步驟2中提供了一個nodejs示例代碼。您將不得不在golang中檢查連接字符串爲mongodb,即golang中的語法。

我發現這篇文章這也解釋了連接到IBM撰寫的MongoDB從的Goland:https://www.compose.com/articles/connect-to-mongo-3-2-on-compose-from-golang/

希望這會有所幫助。