Skip to content

Replace all uses of 'interface{}' with 'any' in the mongo/ packages. #2139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mongo/background_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ func newBackgroundContext(ctx context.Context) context.Context {
}
}

func (b *backgroundContext) Value(key interface{}) interface{} {
func (b *backgroundContext) Value(key any) any {
return b.childValuesCtx.Value(key)
}
2 changes: 1 addition & 1 deletion mongo/batch_cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type batchCursor interface {

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

// MaxAwaitTime returns the maximum amount of time the server will allow
// the operations to execute. This is only valid for tailable awaitData
Expand Down
22 changes: 11 additions & 11 deletions mongo/bulk_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type bulkWriteBatch struct {

// bulkWrite performs a bulkwrite operation
type bulkWrite struct {
comment interface{}
comment any
ordered *bool
bypassDocumentValidation *bool
models []WriteModel
Expand All @@ -38,7 +38,7 @@ type bulkWrite struct {
selector description.ServerSelector
writeConcern *writeconcern.WriteConcern
result BulkWriteResult
let interface{}
let any
rawData *bool
}

Expand All @@ -50,7 +50,7 @@ func (bw *bulkWrite) execute(ctx context.Context) error {

batches := createBatches(bw.models, ordered)
bw.result = BulkWriteResult{
UpsertedIDs: make(map[int64]interface{}),
UpsertedIDs: make(map[int64]any),
}

bwErr := BulkWriteException{
Expand Down Expand Up @@ -105,7 +105,7 @@ func (bw *bulkWrite) execute(ctx context.Context) error {

func (bw *bulkWrite) runBatch(ctx context.Context, batch bulkWriteBatch) (BulkWriteResult, BulkWriteException, error) {
batchRes := BulkWriteResult{
UpsertedIDs: make(map[int64]interface{}),
UpsertedIDs: make(map[int64]any),
}
batchErr := BulkWriteException{}

Expand Down Expand Up @@ -297,9 +297,9 @@ func (bw *bulkWrite) runDelete(ctx context.Context, batch bulkWriteBatch) (opera
}

func createDeleteDoc(
filter interface{},
filter any,
collation *options.Collation,
hint interface{},
hint any,
deleteOne bool,
bsonOpts *options.BSONOptions,
registry *bson.Registry,
Expand Down Expand Up @@ -434,11 +434,11 @@ func (bw *bulkWrite) runUpdate(ctx context.Context, batch bulkWriteBatch) (opera
}

type updateDoc struct {
filter interface{}
update interface{}
hint interface{}
sort interface{}
arrayFilters []interface{}
filter any
update any
hint any
sort any
arrayFilters []any
collation *options.Collation
upsert *bool
multi bool
Expand Down
72 changes: 36 additions & 36 deletions mongo/bulk_write_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type WriteModel interface {
//
// See corresponding setter methods for documentation.
type InsertOneModel struct {
Document interface{}
Document any
}

// NewInsertOneModel creates a new InsertOneModel.
Expand All @@ -34,7 +34,7 @@ func NewInsertOneModel() *InsertOneModel {
// SetDocument specifies the document to be inserted. The document cannot be nil. If it does not have an _id field when
// transformed into BSON, one will be added automatically to the marshalled document. The original document will not be
// modified.
func (iom *InsertOneModel) SetDocument(doc interface{}) *InsertOneModel {
func (iom *InsertOneModel) SetDocument(doc any) *InsertOneModel {
iom.Document = doc
return iom
}
Expand All @@ -45,9 +45,9 @@ func (*InsertOneModel) writeModel() {}
//
// See corresponding setter methods for documentation.
type DeleteOneModel struct {
Filter interface{}
Filter any
Collation *options.Collation
Hint interface{}
Hint any
}

// NewDeleteOneModel creates a new DeleteOneModel.
Expand All @@ -58,7 +58,7 @@ func NewDeleteOneModel() *DeleteOneModel {
// SetFilter specifies a filter to use to select the document to delete. The filter must be a document containing query
// operators. It cannot be nil. If the filter matches multiple documents, one will be selected from the matching
// documents.
func (dom *DeleteOneModel) SetFilter(filter interface{}) *DeleteOneModel {
func (dom *DeleteOneModel) SetFilter(filter any) *DeleteOneModel {
dom.Filter = filter
return dom
}
Expand All @@ -77,7 +77,7 @@ func (dom *DeleteOneModel) SetCollation(collation *options.Collation) *DeleteOne
// if this option is specified during an unacknowledged write operation. The
// driver will return an error if the hint parameter is a multi-key map. The
// default value is nil, which means that no hint will be sent.
func (dom *DeleteOneModel) SetHint(hint interface{}) *DeleteOneModel {
func (dom *DeleteOneModel) SetHint(hint any) *DeleteOneModel {
dom.Hint = hint
return dom
}
Expand All @@ -88,9 +88,9 @@ func (*DeleteOneModel) writeModel() {}
//
// See corresponding setter methods for documentation.
type DeleteManyModel struct {
Filter interface{}
Filter any
Collation *options.Collation
Hint interface{}
Hint any
}

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

// SetFilter specifies a filter to use to select documents to delete. The filter must be a document containing query
// operators. It cannot be nil.
func (dmm *DeleteManyModel) SetFilter(filter interface{}) *DeleteManyModel {
func (dmm *DeleteManyModel) SetFilter(filter any) *DeleteManyModel {
dmm.Filter = filter
return dmm
}
Expand All @@ -119,7 +119,7 @@ func (dmm *DeleteManyModel) SetCollation(collation *options.Collation) *DeleteMa
// if this option is specified during an unacknowledged write operation. The
// driver will return an error if the hint parameter is a multi-key map. The
// default value is nil, which means that no hint will be sent.
func (dmm *DeleteManyModel) SetHint(hint interface{}) *DeleteManyModel {
func (dmm *DeleteManyModel) SetHint(hint any) *DeleteManyModel {
dmm.Hint = hint
return dmm
}
Expand All @@ -132,10 +132,10 @@ func (*DeleteManyModel) writeModel() {}
type ReplaceOneModel struct {
Collation *options.Collation
Upsert *bool
Filter interface{}
Replacement interface{}
Hint interface{}
Sort interface{}
Filter any
Replacement any
Hint any
Sort any
}

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

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

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

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

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

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

// SetArrayFilters specifies a set of filters to determine which elements should be modified when updating an array
// field.
func (uom *UpdateOneModel) SetArrayFilters(filters []interface{}) *UpdateOneModel {
func (uom *UpdateOneModel) SetArrayFilters(filters []any) *UpdateOneModel {
uom.ArrayFilters = filters
return uom
}
Expand All @@ -267,7 +267,7 @@ func (uom *UpdateOneModel) SetUpsert(upsert bool) *UpdateOneModel {
// matched by the sort order will be updated. This option is only valid for MongoDB versions >= 8.0. The sort parameter
// is evaluated sequentially, so the driver will return an error if it is a multi-key map (which is unordeded). The
// default value is nil.
func (uom *UpdateOneModel) SetSort(sort interface{}) *UpdateOneModel {
func (uom *UpdateOneModel) SetSort(sort any) *UpdateOneModel {
uom.Sort = sort
return uom
}
Expand All @@ -280,10 +280,10 @@ func (*UpdateOneModel) writeModel() {}
type UpdateManyModel struct {
Collation *options.Collation
Upsert *bool
Filter interface{}
Update interface{}
ArrayFilters []interface{}
Hint interface{}
Filter any
Update any
ArrayFilters []any
Hint any
}

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

// SetFilter specifies a filter to use to select documents to update. The filter must be a document containing query
// operators. It cannot be nil.
func (umm *UpdateManyModel) SetFilter(filter interface{}) *UpdateManyModel {
func (umm *UpdateManyModel) SetFilter(filter any) *UpdateManyModel {
umm.Filter = filter
return umm
}

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

// SetArrayFilters specifies a set of filters to determine which elements should be modified when updating an array
// field.
func (umm *UpdateManyModel) SetArrayFilters(filters []interface{}) *UpdateManyModel {
func (umm *UpdateManyModel) SetArrayFilters(filters []any) *UpdateManyModel {
umm.ArrayFilters = filters
return umm
}
Expand Down
6 changes: 3 additions & 3 deletions mongo/change_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type changeStreamConfig struct {
crypt driver.Crypt
}

func newChangeStream(ctx context.Context, config changeStreamConfig, pipeline interface{},
func newChangeStream(ctx context.Context, config changeStreamConfig, pipeline any,
opts ...options.Lister[options.ChangeStreamOptions]) (*ChangeStream, error) {
if ctx == nil {
ctx = context.Background()
Expand Down Expand Up @@ -401,7 +401,7 @@ func (cs *ChangeStream) storeResumeToken() error {
return nil
}

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

// Decode will unmarshal the current event document into val and return any errors from the unmarshalling process
// without any modification. If val is nil or is a typed nil, an error will be returned.
func (cs *ChangeStream) Decode(val interface{}) error {
func (cs *ChangeStream) Decode(val any) error {
if cs.cursor == nil {
return ErrNilCursor
}
Expand Down
8 changes: 4 additions & 4 deletions mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type Client struct {
cryptFLE driver.Crypt
metadataClientFLE *Client
internalClientFLE *Client
encryptedFieldsMap map[string]interface{}
encryptedFieldsMap map[string]any
authenticator driver.Authenticator
}

Expand Down Expand Up @@ -681,7 +681,7 @@ func (c *Client) Database(name string, opts ...options.Lister[options.DatabaseOp
// The opts parameter can be used to specify options for this operation (see the options.ListDatabasesOptions documentation).
//
// For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/listDatabases/.
func (c *Client) ListDatabases(ctx context.Context, filter interface{}, opts ...options.Lister[options.ListDatabasesOptions]) (ListDatabasesResult, error) {
func (c *Client) ListDatabases(ctx context.Context, filter any, opts ...options.Lister[options.ListDatabasesOptions]) (ListDatabasesResult, error) {
if ctx == nil {
ctx = context.Background()
}
Expand Down Expand Up @@ -759,7 +759,7 @@ func (c *Client) ListDatabases(ctx context.Context, filter interface{}, opts ...
// documentation.)
//
// For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/listDatabases/.
func (c *Client) ListDatabaseNames(ctx context.Context, filter interface{}, opts ...options.Lister[options.ListDatabasesOptions]) ([]string, error) {
func (c *Client) ListDatabaseNames(ctx context.Context, filter any, opts ...options.Lister[options.ListDatabasesOptions]) ([]string, error) {
opts = append(opts, options.ListDatabases().SetNameOnly(true))

res, err := c.ListDatabases(ctx, filter, opts...)
Expand Down Expand Up @@ -842,7 +842,7 @@ func (c *Client) UseSessionWithOptions(
//
// The opts parameter can be used to specify options for change stream creation (see the options.ChangeStreamOptions
// documentation).
func (c *Client) Watch(ctx context.Context, pipeline interface{},
func (c *Client) Watch(ctx context.Context, pipeline any,
opts ...options.Lister[options.ChangeStreamOptions]) (*ChangeStream, error) {
csConfig := changeStreamConfig{
readConcern: c.readConcern,
Expand Down
Loading
Loading