Skip to content

Commit 3f7ddb9

Browse files
author
Divjot Arora
committed
Change MaxTime and MaxAwaitTime options to always use time.Duration.
GODRIVER-781 Change-Id: Ib5ffdbf2470d939d5be649d87d97c70a98c1dfc4
1 parent 2161eed commit 3f7ddb9

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

mongo/options/countoptions.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
package options
88

9+
import "time"
10+
911
// CountOptions represents all possible options to the count() function
1012
type CountOptions struct {
11-
Collation *Collation // Specifies a collation
12-
Hint interface{} // The index to use
13-
Limit *int64 // The maximum number of documents to count
14-
MaxTime *int64 // The maximum amount of time to allow the operation to run
15-
Skip *int64 // The number of documents to skip before counting
13+
Collation *Collation // Specifies a collation
14+
Hint interface{} // The index to use
15+
Limit *int64 // The maximum number of documents to count
16+
MaxTime *time.Duration // The maximum amount of time to allow the operation to run
17+
Skip *int64 // The number of documents to skip before counting
1618
}
1719

1820
// Count returns a pointer to a new CountOptions
@@ -40,8 +42,8 @@ func (co *CountOptions) SetLimit(i int64) *CountOptions {
4042
}
4143

4244
// SetMaxTime specifies the maximum amount of time to allow the operation to run
43-
func (co *CountOptions) SetMaxTime(i int64) *CountOptions {
44-
co.MaxTime = &i
45+
func (co *CountOptions) SetMaxTime(d time.Duration) *CountOptions {
46+
co.MaxTime = &d
4547
return co
4648
}
4749

mongo/options/distinctoptions.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
package options
88

9+
import "time"
10+
911
// DistinctOptions represents all possible options to the distinct() function
1012
type DistinctOptions struct {
11-
Collation *Collation // Specifies a collation
12-
MaxTime *int64 // The maximum amount of time to allow the operation to run
13+
Collation *Collation // Specifies a collation
14+
MaxTime *time.Duration // The maximum amount of time to allow the operation to run
1315
}
1416

1517
// Distinct returns a pointer to a new DistinctOptions
@@ -25,8 +27,8 @@ func (do *DistinctOptions) SetCollation(c *Collation) *DistinctOptions {
2527
}
2628

2729
// SetMaxTime specifies the maximum amount of time to allow the operation to run
28-
func (do *DistinctOptions) SetMaxTime(i int64) *DistinctOptions {
29-
do.MaxTime = &i
30+
func (do *DistinctOptions) SetMaxTime(d time.Duration) *DistinctOptions {
31+
do.MaxTime = &d
3032
return do
3133
}
3234

mongo/options/estimatedcountoptions.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
package options
88

9+
import "time"
10+
911
// EstimatedDocumentCountOptions represents all possible options to the estimatedDocumentCount() function
1012
type EstimatedDocumentCountOptions struct {
11-
MaxTime *int64 // The maximum amount of time to allow the operation to run
13+
MaxTime *time.Duration // The maximum amount of time to allow the operation to run
1214
}
1315

1416
// EstimatedDocumentCount returns a pointer to a new EstimatedDocumentCountOptions
@@ -17,8 +19,8 @@ func EstimatedDocumentCount() *EstimatedDocumentCountOptions {
1719
}
1820

1921
// SetMaxTime specifies the maximum amount of time to allow the operation to run
20-
func (eco *EstimatedDocumentCountOptions) SetMaxTime(i int64) *EstimatedDocumentCountOptions {
21-
eco.MaxTime = &i
22+
func (eco *EstimatedDocumentCountOptions) SetMaxTime(d time.Duration) *EstimatedDocumentCountOptions {
23+
eco.MaxTime = &d
2224
return eco
2325
}
2426

x/mongo/driver/count.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func Count(
6868
}
6969
if countOpts.MaxTime != nil {
7070
cmd.Opts = append(cmd.Opts, bsonx.Elem{
71-
"maxTimeMS", bsonx.Int64(int64(time.Duration(*countOpts.MaxTime) / time.Millisecond)),
71+
"maxTimeMS", bsonx.Int64(int64(*countOpts.MaxTime / time.Millisecond)),
7272
})
7373
}
7474
if countOpts.Skip != nil {

x/mongo/driver/count_documents.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ package driver
88

99
import (
1010
"context"
11-
"time"
12-
1311
"github.com/mongodb/mongo-go-driver/bson/bsoncodec"
1412
"github.com/mongodb/mongo-go-driver/x/bsonx"
1513

@@ -19,6 +17,7 @@ import (
1917
"github.com/mongodb/mongo-go-driver/x/mongo/driver/uuid"
2018
"github.com/mongodb/mongo-go-driver/x/network/command"
2119
"github.com/mongodb/mongo-go-driver/x/network/description"
20+
"time"
2221
)
2322

2423
// CountDocuments handles the full cycle dispatch and execution of a countDocuments command against the provided
@@ -66,7 +65,7 @@ func CountDocuments(
6665
// ignore Skip and Limit because we already have these options in the pipeline
6766
if countOpts.MaxTime != nil {
6867
cmd.Opts = append(cmd.Opts, bsonx.Elem{
69-
"maxTimeMS", bsonx.Int64(int64(time.Duration(*countOpts.MaxTime) / time.Millisecond)),
68+
"maxTimeMS", bsonx.Int64(int64(*countOpts.MaxTime / time.Millisecond)),
7069
})
7170
}
7271
if countOpts.Collation != nil {

x/mongo/driver/distinct.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ package driver
88

99
import (
1010
"context"
11-
"time"
12-
1311
"github.com/mongodb/mongo-go-driver/mongo/options"
1412
"github.com/mongodb/mongo-go-driver/x/bsonx"
1513

@@ -19,6 +17,7 @@ import (
1917
"github.com/mongodb/mongo-go-driver/x/network/command"
2018
"github.com/mongodb/mongo-go-driver/x/network/description"
2119
"github.com/mongodb/mongo-go-driver/x/network/result"
20+
"time"
2221
)
2322

2423
// Distinct handles the full cycle dispatch and execution of a distinct command against the provided
@@ -64,7 +63,7 @@ func Distinct(
6463

6564
if distinctOpts.MaxTime != nil {
6665
cmd.Opts = append(cmd.Opts, bsonx.Elem{
67-
"maxTimeMS", bsonx.Int64(int64(time.Duration(*distinctOpts.MaxTime) / time.Millisecond)),
66+
"maxTimeMS", bsonx.Int64(int64(*distinctOpts.MaxTime / time.Millisecond)),
6867
})
6968
}
7069
if distinctOpts.Collation != nil {

0 commit comments

Comments
 (0)