Skip to content

Commit 2cbff02

Browse files
authored
GODRIVER-3327 Move option docs from struct fields to setter methods (#1849)
1 parent bfd512a commit 2cbff02

29 files changed

+1077
-1153
lines changed

mongo/options/aggregateoptions.go

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,18 @@ import (
1414

1515
// AggregateOptions represents arguments that can be used to configure an
1616
// Aggregate operation.
17+
//
18+
// See corresponding setter methods for documentation.
1719
type AggregateOptions struct {
18-
// If true, the operation can write to temporary files in the _tmp subdirectory of the database directory path on
19-
// the server. The default value is false.
20-
AllowDiskUse *bool
21-
22-
// The maximum number of documents to be included in each batch returned by the server.
23-
BatchSize *int32
24-
25-
// If true, writes executed as part of the operation will opt out of document-level validation on the server. This
26-
// option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
27-
// false. See https://www.mongodb.com/docs/manual/core/schema-validation/ for more information about document
28-
// validation.
20+
AllowDiskUse *bool
21+
BatchSize *int32
2922
BypassDocumentValidation *bool
30-
31-
// Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
32-
// versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
33-
// default value is nil, which means the default collation of the collection will be used.
34-
Collation *Collation
35-
36-
// The maximum amount of time that the server should wait for new documents to satisfy a tailable cursor query.
37-
// This option is only valid for MongoDB versions >= 3.2 and is ignored for previous server versions.
38-
MaxAwaitTime *time.Duration
39-
40-
// A string or document that will be included in server logs, profiling logs,
41-
// and currentOp queries to help trace the operation. The default is nil,
42-
// which means that no comment will be included in the logs.
43-
Comment interface{}
44-
45-
// The index to use for the aggregation. This should either be the index name as a string or the index specification
46-
// as a document. The hint does not apply to $lookup and $graphLookup aggregation stages. The driver will return an
47-
// error if the hint parameter is a multi-key map. The default value is nil, which means that no hint will be sent.
48-
Hint interface{}
49-
50-
// Specifies parameters for the aggregate expression. This option is only valid for MongoDB versions >= 5.0. Older
51-
// servers will report an error for using this option. This must be a document mapping parameter names to values.
52-
// Values must be constant or closed expressions that do not reference document fields. Parameters can then be
53-
// accessed as variables in an aggregate expression context (e.g. "$$var").
54-
Let interface{}
55-
56-
// Custom options to be added to aggregate expression. Key-value pairs of the BSON map should correlate with desired
57-
// option names and values. Values must be Marshalable. Custom options may conflict with non-custom options, and custom
58-
// options bypass client-side validation. Prefer using non-custom options where possible.
59-
Custom bson.M
23+
Collation *Collation
24+
MaxAwaitTime *time.Duration
25+
Comment interface{}
26+
Hint interface{}
27+
Let interface{}
28+
Custom bson.M
6029
}
6130

6231
// AggregateOptionsBuilder contains options to configure aggregate operations.
@@ -76,7 +45,8 @@ func (ao *AggregateOptionsBuilder) List() []func(*AggregateOptions) error {
7645
return ao.Opts
7746
}
7847

79-
// SetAllowDiskUse sets the value for the AllowDiskUse field.
48+
// SetAllowDiskUse sets the value for the AllowDiskUse field. If true, the operation can write to temporary
49+
// files in the _tmp subdirectory of the database directory path on the server. The default value is false.
8050
func (ao *AggregateOptionsBuilder) SetAllowDiskUse(b bool) *AggregateOptionsBuilder {
8151
ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error {
8252
opts.AllowDiskUse = &b
@@ -87,7 +57,8 @@ func (ao *AggregateOptionsBuilder) SetAllowDiskUse(b bool) *AggregateOptionsBuil
8757
return ao
8858
}
8959

90-
// SetBatchSize sets the value for the BatchSize field.
60+
// SetBatchSize sets the value for the BatchSize field. Specifies the maximum number of documents
61+
// to be included in each batch returned by the server.
9162
func (ao *AggregateOptionsBuilder) SetBatchSize(i int32) *AggregateOptionsBuilder {
9263
ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error {
9364
opts.BatchSize = &i
@@ -98,7 +69,11 @@ func (ao *AggregateOptionsBuilder) SetBatchSize(i int32) *AggregateOptionsBuilde
9869
return ao
9970
}
10071

101-
// SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.
72+
// SetBypassDocumentValidation sets the value for the BypassDocumentValidation field. If true, writes
73+
// executed as part of the operation will opt out of document-level validation on the server. This
74+
// option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value
75+
// is false. See https://www.mongodb.com/docs/manual/core/schema-validation/ for more information about
76+
// document validation.
10277
func (ao *AggregateOptionsBuilder) SetBypassDocumentValidation(b bool) *AggregateOptionsBuilder {
10378
ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error {
10479
opts.BypassDocumentValidation = &b
@@ -109,7 +84,10 @@ func (ao *AggregateOptionsBuilder) SetBypassDocumentValidation(b bool) *Aggregat
10984
return ao
11085
}
11186

112-
// SetCollation sets the value for the Collation field.
87+
// SetCollation sets the value for the Collation field. Specifies a collation to use for string
88+
// comparisons during the operation. This option is only valid for MongoDB versions >= 3.4. For previous
89+
// server versions, the driver will return an error if this option is used. The default value is nil,
90+
// which means the default collation of the collection will be used.
11391
func (ao *AggregateOptionsBuilder) SetCollation(c *Collation) *AggregateOptionsBuilder {
11492
ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error {
11593
opts.Collation = c
@@ -120,7 +98,9 @@ func (ao *AggregateOptionsBuilder) SetCollation(c *Collation) *AggregateOptionsB
12098
return ao
12199
}
122100

123-
// SetMaxAwaitTime sets the value for the MaxAwaitTime field.
101+
// SetMaxAwaitTime sets the value for the MaxAwaitTime field. Specifies maximum amount of time
102+
// that the server should wait for new documents to satisfy a tailable cursor query. This option is
103+
// only valid for MongoDB versions >= 3.2 and is ignored for previous server versions.
124104
func (ao *AggregateOptionsBuilder) SetMaxAwaitTime(d time.Duration) *AggregateOptionsBuilder {
125105
ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error {
126106
opts.MaxAwaitTime = &d
@@ -131,7 +111,9 @@ func (ao *AggregateOptionsBuilder) SetMaxAwaitTime(d time.Duration) *AggregateOp
131111
return ao
132112
}
133113

134-
// SetComment sets the value for the Comment field.
114+
// SetComment sets the value for the Comment field. Specifies a string or document that will be included in
115+
// server logs, profiling logs, and currentOp queries to help trace the operation. The default is nil,
116+
// which means that no comment will be included in the logs.
135117
func (ao *AggregateOptionsBuilder) SetComment(comment interface{}) *AggregateOptionsBuilder {
136118
ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error {
137119
opts.Comment = comment
@@ -142,7 +124,10 @@ func (ao *AggregateOptionsBuilder) SetComment(comment interface{}) *AggregateOpt
142124
return ao
143125
}
144126

145-
// SetHint sets the value for the Hint field.
127+
// SetHint sets the value for the Hint field. Specifies the index to use for the aggregation. This should
128+
// either be the index name as a string or the index specification as a document. The hint does not apply to
129+
// $lookup and $graphLookup aggregation stages. The driver will return an error if the hint parameter
130+
// is a multi-key map. The default value is nil, which means that no hint will be sent.
146131
func (ao *AggregateOptionsBuilder) SetHint(h interface{}) *AggregateOptionsBuilder {
147132
ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error {
148133
opts.Hint = h
@@ -153,7 +138,11 @@ func (ao *AggregateOptionsBuilder) SetHint(h interface{}) *AggregateOptionsBuild
153138
return ao
154139
}
155140

156-
// SetLet sets the value for the Let field.
141+
// SetLet sets the value for the Let field. Specifies parameters for the aggregate expression. This
142+
// option is only valid for MongoDB versions >= 5.0. Older servers will report an error for using this
143+
// option. This must be a document mapping parameter names to values. Values must be constant or closed
144+
// expressions that do not reference document fields. Parameters can then be accessed as variables in
145+
// an aggregate expression context (e.g. "$$var").
157146
func (ao *AggregateOptionsBuilder) SetLet(let interface{}) *AggregateOptionsBuilder {
158147
ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error {
159148
opts.Let = let

mongo/options/autoencryptionoptions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
//
2626
// Enabling In-Use Encryption reduces the maximum document and message size (using a maxBsonObjectSize of 2MiB and
2727
// maxMessageSizeBytes of 6MB) and may have a negative performance impact.
28+
//
29+
// See corresponding setter methods for documentation.
2830
type AutoEncryptionOptions struct {
2931
KeyVaultClientOptions Lister[ClientOptions]
3032
KeyVaultNamespace string

mongo/options/bulkwriteoptions.go

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,13 @@ var DefaultOrdered = true
1111

1212
// BulkWriteOptions represents arguments that can be used to configure a
1313
// BulkWrite operation.
14+
//
15+
// See corresponding setter methods for documentation.
1416
type BulkWriteOptions struct {
15-
// If true, writes executed as part of the operation will opt out of document-level validation on the server. This
16-
// option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
17-
// false. See https://www.mongodb.com/docs/manual/core/schema-validation/ for more information about document
18-
// validation.
1917
BypassDocumentValidation *bool
20-
21-
// A string or document that will be included in server logs, profiling logs, and currentOp queries to help trace
22-
// the operation. The default value is nil, which means that no comment will be included in the logs.
23-
Comment interface{}
24-
25-
// If true, no writes will be executed after one fails. The default value is true.
26-
Ordered *bool
27-
28-
// Specifies parameters for all update and delete commands in the BulkWrite. This option is only valid for MongoDB
29-
// versions >= 5.0. Older servers will report an error for using this option. This must be a document mapping
30-
// parameter names to values. Values must be constant or closed expressions that do not reference document fields.
31-
// Parameters can then be accessed as variables in an aggregate expression context (e.g. "$$var").
32-
Let interface{}
18+
Comment interface{}
19+
Ordered *bool
20+
Let interface{}
3321
}
3422

3523
// BulkWriteOptionsBuilder contains options to configure bulk write operations.
@@ -52,7 +40,9 @@ func (b *BulkWriteOptionsBuilder) List() []func(*BulkWriteOptions) error {
5240
return b.Opts
5341
}
5442

55-
// SetComment sets the value for the Comment field.
43+
// SetComment sets the value for the Comment field. Specifies a string or document that will be included in
44+
// server logs, profiling logs, and currentOp queries to help tracethe operation. The default value is nil,
45+
// which means that no comment will be included in the logs.
5646
func (b *BulkWriteOptionsBuilder) SetComment(comment interface{}) *BulkWriteOptionsBuilder {
5747
b.Opts = append(b.Opts, func(opts *BulkWriteOptions) error {
5848
opts.Comment = comment
@@ -63,7 +53,8 @@ func (b *BulkWriteOptionsBuilder) SetComment(comment interface{}) *BulkWriteOpti
6353
return b
6454
}
6555

66-
// SetOrdered sets the value for the Ordered field.
56+
// SetOrdered sets the value for the Ordered field. If true, no writes will be executed after one fails.
57+
// The default value is true.
6758
func (b *BulkWriteOptionsBuilder) SetOrdered(ordered bool) *BulkWriteOptionsBuilder {
6859
b.Opts = append(b.Opts, func(opts *BulkWriteOptions) error {
6960
opts.Ordered = &ordered
@@ -74,7 +65,11 @@ func (b *BulkWriteOptionsBuilder) SetOrdered(ordered bool) *BulkWriteOptionsBuil
7465
return b
7566
}
7667

77-
// SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.
68+
// SetBypassDocumentValidation sets the value for the BypassDocumentValidation field. If true, writes
69+
// executed as part of the operation will opt out of document-level validation on the server. This option
70+
// is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
71+
// false. See https://www.mongodb.com/docs/manual/core/schema-validation/ for more information about document
72+
// validation.
7873
func (b *BulkWriteOptionsBuilder) SetBypassDocumentValidation(bypass bool) *BulkWriteOptionsBuilder {
7974
b.Opts = append(b.Opts, func(opts *BulkWriteOptions) error {
8075
opts.BypassDocumentValidation = &bypass

0 commit comments

Comments
 (0)