doufan6033
2015-06-17 15:42
浏览 21

Mgo是否缓存连接字符串?

My Go application has been connecting to a MongoDB (hosted on Compose.io) using MGO with no issues.

Today I decided to delete this database and add a different one (again using Compose). I updated the connection string.

So I connect using:

db, err := mgo.Dial("mongodb://<username>:<password>@dogen.mongohq.com:10048/db-name")

with the username and password in place.

Strangely, the application still appears to connect to the old database. I know this because I printed the err message out which told me: not authorized for query on my-old-db-name after I tried to perform a query.

I have run go install to compile again but still no luck.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongpinyao2203 2015-06-17 16:26
    已采纳

    No, mgo does not cache the connection strings you give to the mgo.Dial function. It's not even clear to me what that would mean? Using an incorrect database name after you explicitly asked it to connect to a different database would be a serious bug, rather than caching.

    As for your problem, are you sure you are not referring to the old database name inside your own code? The Dial function is not the only way to specify database names (hint: session.DB)

    点赞 打赏 评论

相关推荐 更多相似问题