Does Mgo cache connection strings?

498 views Asked by At

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

There are 1 answers

1
Gustavo Niemeyer On BEST ANSWER

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)