{"action":"created","issue":{"url":"https://api.github.com/repos/go-mgo/mgo/issues/247","repository_url":"https://api.github.com/repos/go-mgo/mgo","labels_url":"https://api.github.com/repos/go-mgo/mgo/issues/247/labels{/name}","comments_url":"https://api.github.com/repos/go-mgo/mgo/issues/247/comments","events_url":"https://api.github.com/repos/go-mgo/mgo/issues/247/events","html_url":"https://github.com/go-mgo/mgo/issues/247","id":142666621,"number":247,"title":"replicaSet seems to be interpreted as part of the db name","user":{"login":"bejayoharen","id":1331948,"avatar_url":"https://avatars.githubusercontent.com/u/1331948?v=3","gravatar_id":"","url":"https://api.github.com/users/bejayoharen","html_url":"https://github.com/bejayoharen","followers_url":"https://api.github.com/users/bejayoharen/followers","following_url":"https://api.github.com/users/bejayoharen/following{/other_user}","gists_url":"https://api.github.com/users/bejayoharen/gists{/gist_id}","starred_url":"https://api.github.com/users/bejayoharen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bejayoharen/subscriptions","organizations_url":"https://api.github.com/users/bejayoharen/orgs","repos_url":"https://api.github.com/users/bejayoharen/repos","events_url":"https://api.github.com/users/bejayoharen/events{/privacy}","received_events_url":"https://api.github.com/users/bejayoharen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-22T14:27:57Z","updated_at":"2016-03-22T14:40:15Z","closed_at":"2016-03-22T14:40:15Z","body":"When I try to use the replicaSet parameter as part of the mongo URL, I get the following error:\r\n\r\n    not authorized on shimmeo?replicaSet=rs-ds045940 to execute command\r\n\r\nThis seems to suggest that it thinks the database name is `shimmeo?replicaSet=rs-ds045940`, when, in fact, the database name is simply `shimmeo` -- the `?replicaSet=rs-ds045940` should be interpreted as a parameter. I was previously running an old version of mgo, so I purged it. I've updated to the latest version of the driver with\r\n\r\n    go get gopkg.in/mgo.v2\r\n\r\nand updated my includes.\r\n\r\nThe documentation in the source code for the driver seems to indicate that the replicaSet parameter is supported, which makes me think I'm doing something wrong, but I don't know what that might be.\r\n\r\n    //     replicaSet=<setname>\r\n    //\r\n    //         If specified will prevent the obtained session from communicating\r\n    //         with any server which is not part of a replica set with the given name.\r\n    //         The default is to communicate with any server specified or discovered\r\n    //         via the servers contacted.\r\n\r\nHere's the error:\r\n\r\n    2016-03-19T17:10:27.052129+00:00 app[web.1]: ERROR 2016/03/19 17:10:27 future.go:85: Error running future: not authorized on shimmeo?replicaSet=rs-ds045940 to execute command { count: \"FUTURE\", query: { executeafter: { $lte: new Date(1458407427049) } } }\r\n    2016-03-19T17:10:27.060040+00:00 app[web.1]: ERROR 2016/03/19 17:10:27 mongoutil.go:95: not authorized on shimmeo?replicaSet=rs-ds045940 to execute command { createIndexes: \"FUTURE\", indexes: [ { name: \"executeafter_1\", ns: \"shimmeo?replicaSet=rs-ds045940.FUTURE\", key: { executeafter: 1 }, background: true } ] }\r\n    2016-03-19T17:10:27.060151+00:00 app[web.1]: ERROR 2016/03/19 17:10:27 mongoutil.go:96: {[executeafter] false false true false 0  0 0 0 0 0 0   map[]}\r\n    2016-03-19T17:10:27.062398+00:00 app[web.1]: panic: Could not setup Mongo index FUTURE\r\n\r\n\r\nHere's the function that produces the error:\r\n\r\n    func SetupMongoIndices() {\r\n\tsession, err := mgo.Dial(mongouri)\r\n\tif err != nil {\r\n\t\tpanic(\"Could not setup Mongo indices\")\r\n\t}\r\n\tsession.SetMode(mgo.Monotonic, true)\r\n\tdefer session.Close()\r\n\r\n\tfor i, _ := range indexIndices {\r\n\t\tcollection := session.DB(mongodb).C(indexCollectionNames[i])\r\n\t\terr = collection.EnsureIndex(indexIndices[i])\r\n\t\tif err != nil {\r\n\t\t\trevel.ERROR.Print(err)\r\n\t\t\trevel.ERROR.Print(indexIndices[i])\r\n\t\t\tpanic(\"Could not setup Mongo index \" + indexCollectionNames[i])\r\n\t\t}\r\n\t}\r\n    }\r\n"},"comment":{"url":"https://api.github.com/repos/go-mgo/mgo/issues/comments/199843756","html_url":"https://github.com/go-mgo/mgo/issues/247#issuecomment-199843756","issue_url":"https://api.github.com/repos/go-mgo/mgo/issues/247","id":199843756,"user":{"login":"niemeyer","id":378683,"avatar_url":"https://avatars.githubusercontent.com/u/378683?v=3","gravatar_id":"","url":"https://api.github.com/users/niemeyer","html_url":"https://github.com/niemeyer","followers_url":"https://api.github.com/users/niemeyer/followers","following_url":"https://api.github.com/users/niemeyer/following{/other_user}","gists_url":"https://api.github.com/users/niemeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/niemeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niemeyer/subscriptions","organizations_url":"https://api.github.com/users/niemeyer/orgs","repos_url":"https://api.github.com/users/niemeyer/repos","events_url":"https://api.github.com/users/niemeyer/events{/privacy}","received_events_url":"https://api.github.com/users/niemeyer/received_events","type":"User","site_admin":false},"created_at":"2016-03-22T14:40:15Z","updated_at":"2016-03-22T14:40:15Z","body":"Can you please provide a full self-contained example that I can run locally? I suspect that as you do that, you'll find out that this is not really how the string is reaching the driver.\r\n\r\nHere is some evidence that the URL parsing works as it should:\r\n\r\n```\r\n        url, _ := mgo.ParseURL(\"shimmeo?replicaSet=rs-ds045940\")\r\n        fmt.Printf(\"%#v\\n\", url)\r\n```\r\n\r\nOutputs:\r\n\r\n```\r\n&mgo.DialInfo{Addrs:[]string{\"shimmeo\"}, Direct:false, Timeout:0, FailFast:false, Database:\"\", ReplicaSetName:\"rs-ds045940\", Source:\"\", Service:\"\", ServiceHost:\"\", Mechanism:\"\", Username:\"\", Password:\"\", PoolLimit:0, DialServer:(func(*mgo.ServerAddr) (net.Conn, error))(nil), Dial:(func(net.Addr) (net.Conn, error))(nil)}\r\n```\r\n\r\nThat's how `mgo.Dial` parses the URL too.\r\n\r\nPlease reopen the ticket once you get the reproducer."}}