Mgo是否缓存连接字符串?

huangapple go评论84阅读模式
英文:

Does Mgo cache connection strings?

问题

我的Go应用程序一直使用MGO连接到一个托管在Compose.io上的MongoDB,没有任何问题。

今天我决定删除这个数据库并添加一个不同的数据库(再次使用Compose)。我更新了连接字符串。

所以我使用以下方式连接:

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

将用户名和密码替换为实际的值。

奇怪的是,应用程序似乎仍然连接到旧的数据库。我知道这一点是因为我打印了err消息,告诉我在尝试执行查询后出现了not authorized for query on my-old-db-name的错误。

我已经运行了go install重新编译,但仍然没有运气。

英文:

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(&quot;mongodb://&lt;username&gt;:&lt;password&gt;@dogen.mongohq.com:10048/db-name&quot;)

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

得分: 4

不,mgo不会缓存你提供给mgo.Dial函数的连接字符串。我甚至不清楚这意味着什么?如果你明确要求连接到不同的数据库后使用了错误的数据库名称,那将是一个严重的错误,而不是缓存的问题。

至于你的问题,你确定你的代码中没有引用旧的数据库名称吗?Dial函数并不是指定数据库名称的唯一方式(提示:session.DB)。

英文:

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)

huangapple
  • 本文由 发表于 2015年6月17日 23:42:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/30896287.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定