duanquezhan7268 2017-06-15 10:24
浏览 59
已采纳

如何使用golang连接撰写mongodb

I try to connect compose mongodb in bluemix with golang program but i get unsupported connection url option ssl. Here I give mongodb connection string got from composedb console. How to connect with remote host need syntax for connect?

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)
    }

The error:

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
  • 写回答

2条回答 默认 最新

  • duafagm1066 2017-06-29 22:32
    关注

    IBM Bluemix Compose for Mongodb has a documentation available online here: https://console.bluemix.net/docs/services/ComposeForMongoDB/index.html#getting-started-with-compose-for-mongodb

    Step 2 talks about connecting to your compose mongo db. There is a nodejs sample code provided in step 2. You will have to check connection string to mongodb in golang i.e. the syntax in golang.

    I found out this article which explains connecting to IBM Compose mongodb from goland: https://www.compose.com/articles/connect-to-mongo-3-2-on-compose-from-golang/

    hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络
  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开
  • ¥30 crossover21 ARM64版本安装软件问题
  • ¥15 mymetaobjecthandler没有进入
  • ¥15 mmo能不能做客户端怪物
  • ¥15 osm下载到arcgis出错