Skip to content

Commit

Permalink
Fixed shard retrieval (#25)
Browse files Browse the repository at this point in the history
* fixed shard retrieval

* url format fixed
  • Loading branch information
antonsergeyev committed Dec 4, 2020
1 parent 3f6ab52 commit 9a7f147
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gtm.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,10 @@ func (n *N) isCollection() bool {
func (shard *ShardInfo) GetURL() string {
hostParts := strings.SplitN(shard.hostname, "/", 2)
if len(hostParts) == 2 {
return "mongodb://" + hostParts[1] + "?replicaSet=" + hostParts[0]
// there might be multiple comma-separated hosts.
// for now, we just take the first one and ignore the rest.
hosts := strings.Split(hostParts[1], ",")
return "mongodb://" + hosts[0] + "/?replicaSet=" + hostParts[0]
} else {
return "mongodb://" + hostParts[0]
}
Expand Down Expand Up @@ -1711,7 +1714,7 @@ func GetShards(client *mongo.Client) (shardInfos []*ShardInfo) {
// use the hostnames to create multiple clients for a call to StartMulti
col := client.Database("config").Collection("shards")
opts := &options.FindOptions{}
cursor, err := col.Find(context.Background(), nil, opts)
cursor, err := col.Find(context.Background(), bson.D{}, opts)
if err != nil {
return
}
Expand Down

0 comments on commit 9a7f147

Please sign in to comment.