简体   繁体   English

Mgo是否缓存连接字符串?

[英]Does Mgo cache connection strings?

My Go application has been connecting to a MongoDB (hosted on Compose.io) using MGO with no issues. 我的Go应用程序已使用MGO毫无问题地连接到MongoDB(托管在Compose.io上)。

Today I decided to delete this database and add a different one (again using Compose). 今天,我决定删除此数据库并添加另一个数据库(再次使用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. 我知道这一点是因为我打印出一条err消息,告诉我:在尝试执行查询后, 未授权对my-old-db-name进行查询。

I have run go install to compile again but still no luck. 我已经运行过go install可以再次编译,但是仍然没有运气。

No, mgo does not cache the connection strings you give to the mgo.Dial function. 不, mgo不会缓存您提供给mgo.Dial函数的连接字符串。 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 ) Dial函数不是指定数据库名称的唯一方法(提示: session.DB

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM