diff --git a/go.mod b/go.mod index a2c87ad..95ae505 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/tidwall/pretty v1.0.0 // indirect github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect github.com/xdg/stringprep v1.0.0 // indirect - go.mongodb.org/mongo-driver v1.0.4 + go.mongodb.org/mongo-driver v1.1.0 golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect golang.org/x/text v0.3.2 // indirect diff --git a/go.sum b/go.sum index 66424fc..ed37947 100644 --- a/go.sum +++ b/go.sum @@ -17,8 +17,8 @@ github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c h1:u40Z8hqBAAQyv+vATcGgV github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= github.com/xdg/stringprep v1.0.0 h1:d9X0esnoa3dFsV0FG35rAT0RIhYFlPq7MiP+DW89La0= github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= -go.mongodb.org/mongo-driver v1.0.4 h1:bHxbjH6iwh1uInchXadI6hQR107KEbgYsMzoblDONmQ= -go.mongodb.org/mongo-driver v1.0.4/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= +go.mongodb.org/mongo-driver v1.1.0 h1:aeOqSrhl9eDRAap/3T5pCfMBEBxZ0vuXBP+RMtp2KX8= +go.mongodb.org/mongo-driver v1.1.0/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= diff --git a/session.go b/session.go index a72a131..90225b2 100644 --- a/session.go +++ b/session.go @@ -16,7 +16,7 @@ import ( type Session struct { client *mongo.Client collection *mongo.Collection - maxPoolSize uint16 + maxPoolSize uint64 db string uri string m sync.RWMutex @@ -65,7 +65,7 @@ func (s *Session) Collection(collection string) *Collection { } // SetPoolLimit specifies the max size of a server's connection pool. -func (s *Session) SetPoolLimit(limit uint16) { +func (s *Session) SetPoolLimit(limit uint64) { s.m.Lock() s.maxPoolSize = limit s.m.Unlock() @@ -73,9 +73,21 @@ func (s *Session) SetPoolLimit(limit uint16) { // Connect mongo client func (s *Session) Connect() error { + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + defer cancel() opt := options.Client().ApplyURI(s.uri) opt.SetMaxPoolSize(s.maxPoolSize) - client, err := mongo.Connect(context.TODO(), opt) + + client, err := mongo.NewClient(opt) + if err != nil { + return err + } + + err = client.Connect(ctx) + if err != nil { + return err + } + if err != nil { return err } diff --git a/session_test.go b/session_test.go index 3051ce8..957f77a 100644 --- a/session_test.go +++ b/session_test.go @@ -114,7 +114,7 @@ func TestSession_Collection(t *testing.T) { func TestSession_SetPoolLimit(t *testing.T) { type args struct { - limit uint16 + limit uint64 } tests := []struct { name string