Skip to content

Commit 8de46c8

Browse files
committed
Replace all uses of 'interface{}' with 'any' in the mongo/ packages.
1 parent 056ba3c commit 8de46c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+445
-445
lines changed

mongo/background_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ func newBackgroundContext(ctx context.Context) context.Context {
2929
}
3030
}
3131

32-
func (b *backgroundContext) Value(key interface{}) interface{} {
32+
func (b *backgroundContext) Value(key any) any {
3333
return b.childValuesCtx.Value(key)
3434
}

mongo/batch_cursor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type batchCursor interface {
5050

5151
// SetComment will set a user-configurable comment that can be used to
5252
// identify the operation in server logs.
53-
SetComment(interface{})
53+
SetComment(any)
5454
}
5555

5656
// changeStreamCursor is the interface implemented by batch cursors that also provide the functionality for retrieving

mongo/bulk_write.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type bulkWriteBatch struct {
2929

3030
// bulkWrite performs a bulkwrite operation
3131
type bulkWrite struct {
32-
comment interface{}
32+
comment any
3333
ordered *bool
3434
bypassDocumentValidation *bool
3535
models []WriteModel
@@ -38,7 +38,7 @@ type bulkWrite struct {
3838
selector description.ServerSelector
3939
writeConcern *writeconcern.WriteConcern
4040
result BulkWriteResult
41-
let interface{}
41+
let any
4242
}
4343

4444
func (bw *bulkWrite) execute(ctx context.Context) error {
@@ -49,7 +49,7 @@ func (bw *bulkWrite) execute(ctx context.Context) error {
4949

5050
batches := createBatches(bw.models, ordered)
5151
bw.result = BulkWriteResult{
52-
UpsertedIDs: make(map[int64]interface{}),
52+
UpsertedIDs: make(map[int64]any),
5353
}
5454

5555
bwErr := BulkWriteException{
@@ -104,7 +104,7 @@ func (bw *bulkWrite) execute(ctx context.Context) error {
104104

105105
func (bw *bulkWrite) runBatch(ctx context.Context, batch bulkWriteBatch) (BulkWriteResult, BulkWriteException, error) {
106106
batchRes := BulkWriteResult{
107-
UpsertedIDs: make(map[int64]interface{}),
107+
UpsertedIDs: make(map[int64]any),
108108
}
109109
batchErr := BulkWriteException{}
110110

@@ -288,9 +288,9 @@ func (bw *bulkWrite) runDelete(ctx context.Context, batch bulkWriteBatch) (opera
288288
}
289289

290290
func createDeleteDoc(
291-
filter interface{},
291+
filter any,
292292
collation *options.Collation,
293-
hint interface{},
293+
hint any,
294294
deleteOne bool,
295295
bsonOpts *options.BSONOptions,
296296
registry *bson.Registry,
@@ -421,11 +421,11 @@ func (bw *bulkWrite) runUpdate(ctx context.Context, batch bulkWriteBatch) (opera
421421
}
422422

423423
type updateDoc struct {
424-
filter interface{}
425-
update interface{}
426-
hint interface{}
427-
sort interface{}
428-
arrayFilters []interface{}
424+
filter any
425+
update any
426+
hint any
427+
sort any
428+
arrayFilters []any
429429
collation *options.Collation
430430
upsert *bool
431431
multi bool

mongo/bulk_write_models.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type WriteModel interface {
2323
//
2424
// See corresponding setter methods for documentation.
2525
type InsertOneModel struct {
26-
Document interface{}
26+
Document any
2727
}
2828

2929
// NewInsertOneModel creates a new InsertOneModel.
@@ -34,7 +34,7 @@ func NewInsertOneModel() *InsertOneModel {
3434
// SetDocument specifies the document to be inserted. The document cannot be nil. If it does not have an _id field when
3535
// transformed into BSON, one will be added automatically to the marshalled document. The original document will not be
3636
// modified.
37-
func (iom *InsertOneModel) SetDocument(doc interface{}) *InsertOneModel {
37+
func (iom *InsertOneModel) SetDocument(doc any) *InsertOneModel {
3838
iom.Document = doc
3939
return iom
4040
}
@@ -45,9 +45,9 @@ func (*InsertOneModel) writeModel() {}
4545
//
4646
// See corresponding setter methods for documentation.
4747
type DeleteOneModel struct {
48-
Filter interface{}
48+
Filter any
4949
Collation *options.Collation
50-
Hint interface{}
50+
Hint any
5151
}
5252

5353
// NewDeleteOneModel creates a new DeleteOneModel.
@@ -58,7 +58,7 @@ func NewDeleteOneModel() *DeleteOneModel {
5858
// SetFilter specifies a filter to use to select the document to delete. The filter must be a document containing query
5959
// operators. It cannot be nil. If the filter matches multiple documents, one will be selected from the matching
6060
// documents.
61-
func (dom *DeleteOneModel) SetFilter(filter interface{}) *DeleteOneModel {
61+
func (dom *DeleteOneModel) SetFilter(filter any) *DeleteOneModel {
6262
dom.Filter = filter
6363
return dom
6464
}
@@ -77,7 +77,7 @@ func (dom *DeleteOneModel) SetCollation(collation *options.Collation) *DeleteOne
7777
// if this option is specified during an unacknowledged write operation. The
7878
// driver will return an error if the hint parameter is a multi-key map. The
7979
// default value is nil, which means that no hint will be sent.
80-
func (dom *DeleteOneModel) SetHint(hint interface{}) *DeleteOneModel {
80+
func (dom *DeleteOneModel) SetHint(hint any) *DeleteOneModel {
8181
dom.Hint = hint
8282
return dom
8383
}
@@ -88,9 +88,9 @@ func (*DeleteOneModel) writeModel() {}
8888
//
8989
// See corresponding setter methods for documentation.
9090
type DeleteManyModel struct {
91-
Filter interface{}
91+
Filter any
9292
Collation *options.Collation
93-
Hint interface{}
93+
Hint any
9494
}
9595

9696
// NewDeleteManyModel creates a new DeleteManyModel.
@@ -100,7 +100,7 @@ func NewDeleteManyModel() *DeleteManyModel {
100100

101101
// SetFilter specifies a filter to use to select documents to delete. The filter must be a document containing query
102102
// operators. It cannot be nil.
103-
func (dmm *DeleteManyModel) SetFilter(filter interface{}) *DeleteManyModel {
103+
func (dmm *DeleteManyModel) SetFilter(filter any) *DeleteManyModel {
104104
dmm.Filter = filter
105105
return dmm
106106
}
@@ -119,7 +119,7 @@ func (dmm *DeleteManyModel) SetCollation(collation *options.Collation) *DeleteMa
119119
// if this option is specified during an unacknowledged write operation. The
120120
// driver will return an error if the hint parameter is a multi-key map. The
121121
// default value is nil, which means that no hint will be sent.
122-
func (dmm *DeleteManyModel) SetHint(hint interface{}) *DeleteManyModel {
122+
func (dmm *DeleteManyModel) SetHint(hint any) *DeleteManyModel {
123123
dmm.Hint = hint
124124
return dmm
125125
}
@@ -132,10 +132,10 @@ func (*DeleteManyModel) writeModel() {}
132132
type ReplaceOneModel struct {
133133
Collation *options.Collation
134134
Upsert *bool
135-
Filter interface{}
136-
Replacement interface{}
137-
Hint interface{}
138-
Sort interface{}
135+
Filter any
136+
Replacement any
137+
Hint any
138+
Sort any
139139
}
140140

141141
// NewReplaceOneModel creates a new ReplaceOneModel.
@@ -150,22 +150,22 @@ func NewReplaceOneModel() *ReplaceOneModel {
150150
// if this option is specified during an unacknowledged write operation. The
151151
// driver will return an error if the hint parameter is a multi-key map. The
152152
// default value is nil, which means that no hint will be sent.
153-
func (rom *ReplaceOneModel) SetHint(hint interface{}) *ReplaceOneModel {
153+
func (rom *ReplaceOneModel) SetHint(hint any) *ReplaceOneModel {
154154
rom.Hint = hint
155155
return rom
156156
}
157157

158158
// SetFilter specifies a filter to use to select the document to replace. The filter must be a document containing query
159159
// operators. It cannot be nil. If the filter matches multiple documents, one will be selected from the matching
160160
// documents.
161-
func (rom *ReplaceOneModel) SetFilter(filter interface{}) *ReplaceOneModel {
161+
func (rom *ReplaceOneModel) SetFilter(filter any) *ReplaceOneModel {
162162
rom.Filter = filter
163163
return rom
164164
}
165165

166166
// SetReplacement specifies a document that will be used to replace the selected document. It cannot be nil and cannot
167167
// contain any update operators (https://www.mongodb.com/docs/manual/reference/operator/update/).
168-
func (rom *ReplaceOneModel) SetReplacement(rep interface{}) *ReplaceOneModel {
168+
func (rom *ReplaceOneModel) SetReplacement(rep any) *ReplaceOneModel {
169169
rom.Replacement = rep
170170
return rom
171171
}
@@ -189,7 +189,7 @@ func (rom *ReplaceOneModel) SetUpsert(upsert bool) *ReplaceOneModel {
189189
// matched by the sort order will be replaced. This option is only valid for MongoDB versions >= 8.0. The sort parameter
190190
// is evaluated sequentially, so the driver will return an error if it is a multi-key map (which is unordeded). The
191191
// default value is nil.
192-
func (rom *ReplaceOneModel) SetSort(sort interface{}) *ReplaceOneModel {
192+
func (rom *ReplaceOneModel) SetSort(sort any) *ReplaceOneModel {
193193
rom.Sort = sort
194194
return rom
195195
}
@@ -202,11 +202,11 @@ func (*ReplaceOneModel) writeModel() {}
202202
type UpdateOneModel struct {
203203
Collation *options.Collation
204204
Upsert *bool
205-
Filter interface{}
206-
Update interface{}
207-
ArrayFilters []interface{}
208-
Hint interface{}
209-
Sort interface{}
205+
Filter any
206+
Update any
207+
ArrayFilters []any
208+
Hint any
209+
Sort any
210210
}
211211

212212
// NewUpdateOneModel creates a new UpdateOneModel.
@@ -221,29 +221,29 @@ func NewUpdateOneModel() *UpdateOneModel {
221221
// if this option is specified during an unacknowledged write operation. The
222222
// driver will return an error if the hint parameter is a multi-key map. The
223223
// default value is nil, which means that no hint will be sent.
224-
func (uom *UpdateOneModel) SetHint(hint interface{}) *UpdateOneModel {
224+
func (uom *UpdateOneModel) SetHint(hint any) *UpdateOneModel {
225225
uom.Hint = hint
226226
return uom
227227
}
228228

229229
// SetFilter specifies a filter to use to select the document to update. The filter must be a document containing query
230230
// operators. It cannot be nil. If the filter matches multiple documents, one will be selected from the matching
231231
// documents.
232-
func (uom *UpdateOneModel) SetFilter(filter interface{}) *UpdateOneModel {
232+
func (uom *UpdateOneModel) SetFilter(filter any) *UpdateOneModel {
233233
uom.Filter = filter
234234
return uom
235235
}
236236

237237
// SetUpdate specifies the modifications to be made to the selected document. The value must be a document containing
238238
// update operators (https://www.mongodb.com/docs/manual/reference/operator/update/). It cannot be nil or empty.
239-
func (uom *UpdateOneModel) SetUpdate(update interface{}) *UpdateOneModel {
239+
func (uom *UpdateOneModel) SetUpdate(update any) *UpdateOneModel {
240240
uom.Update = update
241241
return uom
242242
}
243243

244244
// SetArrayFilters specifies a set of filters to determine which elements should be modified when updating an array
245245
// field.
246-
func (uom *UpdateOneModel) SetArrayFilters(filters []interface{}) *UpdateOneModel {
246+
func (uom *UpdateOneModel) SetArrayFilters(filters []any) *UpdateOneModel {
247247
uom.ArrayFilters = filters
248248
return uom
249249
}
@@ -267,7 +267,7 @@ func (uom *UpdateOneModel) SetUpsert(upsert bool) *UpdateOneModel {
267267
// matched by the sort order will be updated. This option is only valid for MongoDB versions >= 8.0. The sort parameter
268268
// is evaluated sequentially, so the driver will return an error if it is a multi-key map (which is unordeded). The
269269
// default value is nil.
270-
func (uom *UpdateOneModel) SetSort(sort interface{}) *UpdateOneModel {
270+
func (uom *UpdateOneModel) SetSort(sort any) *UpdateOneModel {
271271
uom.Sort = sort
272272
return uom
273273
}
@@ -280,10 +280,10 @@ func (*UpdateOneModel) writeModel() {}
280280
type UpdateManyModel struct {
281281
Collation *options.Collation
282282
Upsert *bool
283-
Filter interface{}
284-
Update interface{}
285-
ArrayFilters []interface{}
286-
Hint interface{}
283+
Filter any
284+
Update any
285+
ArrayFilters []any
286+
Hint any
287287
}
288288

289289
// NewUpdateManyModel creates a new UpdateManyModel.
@@ -298,28 +298,28 @@ func NewUpdateManyModel() *UpdateManyModel {
298298
// if this option is specified during an unacknowledged write operation. The
299299
// driver will return an error if the hint parameter is a multi-key map. The
300300
// default value is nil, which means that no hint will be sent.
301-
func (umm *UpdateManyModel) SetHint(hint interface{}) *UpdateManyModel {
301+
func (umm *UpdateManyModel) SetHint(hint any) *UpdateManyModel {
302302
umm.Hint = hint
303303
return umm
304304
}
305305

306306
// SetFilter specifies a filter to use to select documents to update. The filter must be a document containing query
307307
// operators. It cannot be nil.
308-
func (umm *UpdateManyModel) SetFilter(filter interface{}) *UpdateManyModel {
308+
func (umm *UpdateManyModel) SetFilter(filter any) *UpdateManyModel {
309309
umm.Filter = filter
310310
return umm
311311
}
312312

313313
// SetUpdate specifies the modifications to be made to the selected documents. The value must be a document containing
314314
// update operators (https://www.mongodb.com/docs/manual/reference/operator/update/). It cannot be nil or empty.
315-
func (umm *UpdateManyModel) SetUpdate(update interface{}) *UpdateManyModel {
315+
func (umm *UpdateManyModel) SetUpdate(update any) *UpdateManyModel {
316316
umm.Update = update
317317
return umm
318318
}
319319

320320
// SetArrayFilters specifies a set of filters to determine which elements should be modified when updating an array
321321
// field.
322-
func (umm *UpdateManyModel) SetArrayFilters(filters []interface{}) *UpdateManyModel {
322+
func (umm *UpdateManyModel) SetArrayFilters(filters []any) *UpdateManyModel {
323323
umm.ArrayFilters = filters
324324
return umm
325325
}

mongo/change_stream.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func validChangeStreamTimeouts(ctx context.Context, cs *ChangeStream) bool {
130130
return *timeout <= 0 || *maxAwaitTime < *timeout
131131
}
132132

133-
func newChangeStream(ctx context.Context, config changeStreamConfig, pipeline interface{},
133+
func newChangeStream(ctx context.Context, config changeStreamConfig, pipeline any,
134134
opts ...options.Lister[options.ChangeStreamOptions]) (*ChangeStream, error) {
135135
if ctx == nil {
136136
ctx = context.Background()
@@ -429,7 +429,7 @@ func (cs *ChangeStream) storeResumeToken() error {
429429
return nil
430430
}
431431

432-
func (cs *ChangeStream) buildPipelineSlice(pipeline interface{}) error {
432+
func (cs *ChangeStream) buildPipelineSlice(pipeline any) error {
433433
val := reflect.ValueOf(pipeline)
434434
if !val.IsValid() || !(val.Kind() == reflect.Slice) {
435435
cs.err = errors.New("can only marshal slices and arrays into aggregation pipelines, but got invalid")
@@ -585,7 +585,7 @@ func (cs *ChangeStream) SetBatchSize(size int32) {
585585

586586
// Decode will unmarshal the current event document into val and return any errors from the unmarshalling process
587587
// without any modification. If val is nil or is a typed nil, an error will be returned.
588-
func (cs *ChangeStream) Decode(val interface{}) error {
588+
func (cs *ChangeStream) Decode(val any) error {
589589
if cs.cursor == nil {
590590
return ErrNilCursor
591591
}

mongo/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ type Client struct {
8282
cryptFLE driver.Crypt
8383
metadataClientFLE *Client
8484
internalClientFLE *Client
85-
encryptedFieldsMap map[string]interface{}
85+
encryptedFieldsMap map[string]any
8686
authenticator driver.Authenticator
8787
}
8888

@@ -680,7 +680,7 @@ func (c *Client) Database(name string, opts ...options.Lister[options.DatabaseOp
680680
// The opts parameter can be used to specify options for this operation (see the options.ListDatabasesOptions documentation).
681681
//
682682
// For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/listDatabases/.
683-
func (c *Client) ListDatabases(ctx context.Context, filter interface{}, opts ...options.Lister[options.ListDatabasesOptions]) (ListDatabasesResult, error) {
683+
func (c *Client) ListDatabases(ctx context.Context, filter any, opts ...options.Lister[options.ListDatabasesOptions]) (ListDatabasesResult, error) {
684684
if ctx == nil {
685685
ctx = context.Background()
686686
}
@@ -758,7 +758,7 @@ func (c *Client) ListDatabases(ctx context.Context, filter interface{}, opts ...
758758
// documentation.)
759759
//
760760
// For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/listDatabases/.
761-
func (c *Client) ListDatabaseNames(ctx context.Context, filter interface{}, opts ...options.Lister[options.ListDatabasesOptions]) ([]string, error) {
761+
func (c *Client) ListDatabaseNames(ctx context.Context, filter any, opts ...options.Lister[options.ListDatabasesOptions]) ([]string, error) {
762762
opts = append(opts, options.ListDatabases().SetNameOnly(true))
763763

764764
res, err := c.ListDatabases(ctx, filter, opts...)
@@ -841,7 +841,7 @@ func (c *Client) UseSessionWithOptions(
841841
//
842842
// The opts parameter can be used to specify options for change stream creation (see the options.ChangeStreamOptions
843843
// documentation).
844-
func (c *Client) Watch(ctx context.Context, pipeline interface{},
844+
func (c *Client) Watch(ctx context.Context, pipeline any,
845845
opts ...options.Lister[options.ChangeStreamOptions]) (*ChangeStream, error) {
846846
csConfig := changeStreamConfig{
847847
readConcern: c.readConcern,

0 commit comments

Comments
 (0)