diff --git a/mongo/background_context.go b/mongo/background_context.go index e4146e8b7c..0fac086899 100644 --- a/mongo/background_context.go +++ b/mongo/background_context.go @@ -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) } diff --git a/mongo/batch_cursor.go b/mongo/batch_cursor.go index 4781812dac..fc6f76040a 100644 --- a/mongo/batch_cursor.go +++ b/mongo/batch_cursor.go @@ -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 diff --git a/mongo/bulk_write.go b/mongo/bulk_write.go index 7a3181c6c4..036e3badb1 100644 --- a/mongo/bulk_write.go +++ b/mongo/bulk_write.go @@ -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 @@ -38,7 +38,7 @@ type bulkWrite struct { selector description.ServerSelector writeConcern *writeconcern.WriteConcern result BulkWriteResult - let interface{} + let any rawData *bool } @@ -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{ @@ -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{} @@ -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, @@ -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 diff --git a/mongo/bulk_write_models.go b/mongo/bulk_write_models.go index fac0817b6c..f28af163b1 100644 --- a/mongo/bulk_write_models.go +++ b/mongo/bulk_write_models.go @@ -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. @@ -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 } @@ -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. @@ -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 } @@ -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 } @@ -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. @@ -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 } @@ -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 } @@ -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. @@ -150,7 +150,7 @@ 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 } @@ -158,14 +158,14 @@ func (rom *ReplaceOneModel) SetHint(hint interface{}) *ReplaceOneModel { // 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 } @@ -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 } @@ -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. @@ -221,7 +221,7 @@ 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 } @@ -229,21 +229,21 @@ func (uom *UpdateOneModel) SetHint(hint interface{}) *UpdateOneModel { // 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 } @@ -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 } @@ -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. @@ -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 } diff --git a/mongo/change_stream.go b/mongo/change_stream.go index 6f0ca8a084..d5ad8058ec 100644 --- a/mongo/change_stream.go +++ b/mongo/change_stream.go @@ -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() @@ -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") @@ -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 } diff --git a/mongo/client.go b/mongo/client.go index 9140e178af..cb2e54944e 100644 --- a/mongo/client.go +++ b/mongo/client.go @@ -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 } @@ -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() } @@ -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...) @@ -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, diff --git a/mongo/client_bulk_write.go b/mongo/client_bulk_write.go index 7a0d557881..310fdbc301 100644 --- a/mongo/client_bulk_write.go +++ b/mongo/client_bulk_write.go @@ -30,7 +30,7 @@ const ( type clientBulkWritePair struct { namespace string - model interface{} + model any } type clientBulkWrite struct { @@ -38,8 +38,8 @@ type clientBulkWrite struct { errorsOnly bool ordered *bool bypassDocumentValidation *bool - comment interface{} - let interface{} + comment any + let any session *session.Client client *Client selector description.ServerSelector @@ -161,7 +161,7 @@ type cursorInfo struct { N int32 NModified *int32 Upserted *struct { - ID interface{} `bson:"_id"` + ID any `bson:"_id"` } } @@ -193,7 +193,7 @@ type modelBatches struct { retryMode driver.RetryMode // RetryNone by default cursorHandlers []func(*cursorInfo, bson.Raw) bool - newIDMap map[int]interface{} + newIDMap map[int]any result *ClientBulkWriteResult writeConcernErrors []WriteConcernError @@ -266,7 +266,7 @@ func (mb *modelBatches) appendBatches(fn functionSet, dst []byte, maxCount, tota } mb.cursorHandlers = mb.cursorHandlers[:0] - mb.newIDMap = make(map[int]interface{}) + mb.newIDMap = make(map[int]any) nsMap := make(map[string]int) getNsIndex := func(namespace string) (int, bool) { @@ -301,7 +301,7 @@ func (mb *modelBatches) appendBatches(fn functionSet, dst []byte, maxCount, tota switch model := mb.writePairs[i].model.(type) { case *ClientInsertOneModel: mb.cursorHandlers = append(mb.cursorHandlers, mb.appendInsertResult) - var id interface{} + var id any id, doc, err = (&clientInsertDoc{ namespace: nsIdx, document: model.Document, @@ -582,10 +582,10 @@ func (mb *modelBatches) appendUpdateResult(cur *cursorInfo, raw bson.Raw) bool { type clientInsertDoc struct { namespace int - document interface{} + document any } -func (d *clientInsertDoc) marshal(bsonOpts *options.BSONOptions, registry *bson.Registry) (interface{}, bsoncore.Document, error) { +func (d *clientInsertDoc) marshal(bsonOpts *options.BSONOptions, registry *bson.Registry) (any, bsoncore.Document, error) { uidx, doc := bsoncore.AppendDocumentStart(nil) doc = bsoncore.AppendInt32Element(doc, "insert", int32(d.namespace)) @@ -593,7 +593,7 @@ func (d *clientInsertDoc) marshal(bsonOpts *options.BSONOptions, registry *bson. if err != nil { return nil, nil, err } - var id interface{} + var id any f, id, err = ensureID(f, bson.NilObjectID, bsonOpts, registry) if err != nil { return nil, nil, err @@ -605,12 +605,12 @@ func (d *clientInsertDoc) marshal(bsonOpts *options.BSONOptions, registry *bson. type clientUpdateDoc struct { namespace int - filter interface{} - update interface{} - hint interface{} - arrayFilters []interface{} + filter any + update any + hint any + arrayFilters []any collation *options.Collation - sort interface{} + sort any upsert *bool multi bool checkDollarKey bool @@ -681,9 +681,9 @@ func (d *clientUpdateDoc) marshal(bsonOpts *options.BSONOptions, registry *bson. type clientDeleteDoc struct { namespace int - filter interface{} + filter any collation *options.Collation - hint interface{} + hint any multi bool } diff --git a/mongo/client_bulk_write_models.go b/mongo/client_bulk_write_models.go index 87550eee1f..da0ea18e3d 100644 --- a/mongo/client_bulk_write_models.go +++ b/mongo/client_bulk_write_models.go @@ -24,7 +24,7 @@ type ClientWriteModel interface { // // See corresponding setter methods for documentation. type ClientInsertOneModel struct { - Document interface{} + Document any } // NewClientInsertOneModel creates a new ClientInsertOneModel. @@ -37,7 +37,7 @@ func (*ClientInsertOneModel) clientWriteModel() {} // 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 *ClientInsertOneModel) SetDocument(doc interface{}) *ClientInsertOneModel { +func (iom *ClientInsertOneModel) SetDocument(doc any) *ClientInsertOneModel { iom.Document = doc return iom } @@ -48,11 +48,11 @@ func (iom *ClientInsertOneModel) SetDocument(doc interface{}) *ClientInsertOneMo type ClientUpdateOneModel 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 } // NewClientUpdateOneModel creates a new ClientUpdateOneModel. @@ -64,7 +64,7 @@ func (*ClientUpdateOneModel) clientWriteModel() {} // SetHint specifies the index to use for the operation. This should either be the index name as a string or the index // specification as a document. The default value is nil, which means that no hint will be sent. -func (uom *ClientUpdateOneModel) SetHint(hint interface{}) *ClientUpdateOneModel { +func (uom *ClientUpdateOneModel) SetHint(hint any) *ClientUpdateOneModel { uom.Hint = hint return uom } @@ -72,21 +72,21 @@ func (uom *ClientUpdateOneModel) SetHint(hint interface{}) *ClientUpdateOneModel // 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 *ClientUpdateOneModel) SetFilter(filter interface{}) *ClientUpdateOneModel { +func (uom *ClientUpdateOneModel) SetFilter(filter any) *ClientUpdateOneModel { 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 *ClientUpdateOneModel) SetUpdate(update interface{}) *ClientUpdateOneModel { +func (uom *ClientUpdateOneModel) SetUpdate(update any) *ClientUpdateOneModel { 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 *ClientUpdateOneModel) SetArrayFilters(filters []interface{}) *ClientUpdateOneModel { +func (uom *ClientUpdateOneModel) SetArrayFilters(filters []any) *ClientUpdateOneModel { uom.ArrayFilters = filters return uom } @@ -110,7 +110,7 @@ func (uom *ClientUpdateOneModel) SetUpsert(upsert bool) *ClientUpdateOneModel { // 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 *ClientUpdateOneModel) SetSort(sort interface{}) *ClientUpdateOneModel { +func (uom *ClientUpdateOneModel) SetSort(sort any) *ClientUpdateOneModel { uom.Sort = sort return uom } @@ -121,10 +121,10 @@ func (uom *ClientUpdateOneModel) SetSort(sort interface{}) *ClientUpdateOneModel type ClientUpdateManyModel struct { Collation *options.Collation Upsert *bool - Filter interface{} - Update interface{} - ArrayFilters []interface{} - Hint interface{} + Filter any + Update any + ArrayFilters []any + Hint any } // NewClientUpdateManyModel creates a new ClientUpdateManyModel. @@ -136,28 +136,28 @@ func (*ClientUpdateManyModel) clientWriteModel() {} // SetHint specifies the index to use for the operation. This should either be the index name as a string or the index // specification as a document. The default value is nil, which means that no hint will be sent. -func (umm *ClientUpdateManyModel) SetHint(hint interface{}) *ClientUpdateManyModel { +func (umm *ClientUpdateManyModel) SetHint(hint any) *ClientUpdateManyModel { 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 *ClientUpdateManyModel) SetFilter(filter interface{}) *ClientUpdateManyModel { +func (umm *ClientUpdateManyModel) SetFilter(filter any) *ClientUpdateManyModel { 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 *ClientUpdateManyModel) SetUpdate(update interface{}) *ClientUpdateManyModel { +func (umm *ClientUpdateManyModel) SetUpdate(update any) *ClientUpdateManyModel { 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 *ClientUpdateManyModel) SetArrayFilters(filters []interface{}) *ClientUpdateManyModel { +func (umm *ClientUpdateManyModel) SetArrayFilters(filters []any) *ClientUpdateManyModel { umm.ArrayFilters = filters return umm } @@ -183,10 +183,10 @@ func (umm *ClientUpdateManyModel) SetUpsert(upsert bool) *ClientUpdateManyModel type ClientReplaceOneModel struct { Collation *options.Collation Upsert *bool - Filter interface{} - Replacement interface{} - Hint interface{} - Sort interface{} + Filter any + Replacement any + Hint any + Sort any } // NewClientReplaceOneModel creates a new ClientReplaceOneModel. @@ -198,7 +198,7 @@ func (*ClientReplaceOneModel) clientWriteModel() {} // SetHint specifies the index to use for the operation. This should either be the index name as a string or the index // specification as a document. The default value is nil, which means that no hint will be sent. -func (rom *ClientReplaceOneModel) SetHint(hint interface{}) *ClientReplaceOneModel { +func (rom *ClientReplaceOneModel) SetHint(hint any) *ClientReplaceOneModel { rom.Hint = hint return rom } @@ -206,14 +206,14 @@ func (rom *ClientReplaceOneModel) SetHint(hint interface{}) *ClientReplaceOneMod // 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 *ClientReplaceOneModel) SetFilter(filter interface{}) *ClientReplaceOneModel { +func (rom *ClientReplaceOneModel) SetFilter(filter any) *ClientReplaceOneModel { 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 *ClientReplaceOneModel) SetReplacement(rep interface{}) *ClientReplaceOneModel { +func (rom *ClientReplaceOneModel) SetReplacement(rep any) *ClientReplaceOneModel { rom.Replacement = rep return rom } @@ -237,7 +237,7 @@ func (rom *ClientReplaceOneModel) SetUpsert(upsert bool) *ClientReplaceOneModel // 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 *ClientReplaceOneModel) SetSort(sort interface{}) *ClientReplaceOneModel { +func (rom *ClientReplaceOneModel) SetSort(sort any) *ClientReplaceOneModel { rom.Sort = sort return rom } @@ -246,9 +246,9 @@ func (rom *ClientReplaceOneModel) SetSort(sort interface{}) *ClientReplaceOneMod // // See corresponding setter methods for documentation. type ClientDeleteOneModel struct { - Filter interface{} + Filter any Collation *options.Collation - Hint interface{} + Hint any } // NewClientDeleteOneModel creates a new ClientDeleteOneModel. @@ -261,7 +261,7 @@ func (*ClientDeleteOneModel) clientWriteModel() {} // 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 *ClientDeleteOneModel) SetFilter(filter interface{}) *ClientDeleteOneModel { +func (dom *ClientDeleteOneModel) SetFilter(filter any) *ClientDeleteOneModel { dom.Filter = filter return dom } @@ -275,7 +275,7 @@ func (dom *ClientDeleteOneModel) SetCollation(collation *options.Collation) *Cli // SetHint specifies the index to use for the operation. This should either be the index name as a string or the index // specification as a document. The default value is nil, which means that no hint will be sent. -func (dom *ClientDeleteOneModel) SetHint(hint interface{}) *ClientDeleteOneModel { +func (dom *ClientDeleteOneModel) SetHint(hint any) *ClientDeleteOneModel { dom.Hint = hint return dom } @@ -284,9 +284,9 @@ func (dom *ClientDeleteOneModel) SetHint(hint interface{}) *ClientDeleteOneModel // // See corresponding setter methods for documentation. type ClientDeleteManyModel struct { - Filter interface{} + Filter any Collation *options.Collation - Hint interface{} + Hint any } // NewClientDeleteManyModel creates a new ClientDeleteManyModel. @@ -298,7 +298,7 @@ func (*ClientDeleteManyModel) clientWriteModel() {} // 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 *ClientDeleteManyModel) SetFilter(filter interface{}) *ClientDeleteManyModel { +func (dmm *ClientDeleteManyModel) SetFilter(filter any) *ClientDeleteManyModel { dmm.Filter = filter return dmm } @@ -312,7 +312,7 @@ func (dmm *ClientDeleteManyModel) SetCollation(collation *options.Collation) *Cl // SetHint specifies the index to use for the operation. This should either be the index name as a string or the index // specification as a document. The default value is nil, which means that no hint will be sent. -func (dmm *ClientDeleteManyModel) SetHint(hint interface{}) *ClientDeleteManyModel { +func (dmm *ClientDeleteManyModel) SetHint(hint any) *ClientDeleteManyModel { dmm.Hint = hint return dmm } diff --git a/mongo/client_encryption.go b/mongo/client_encryption.go index dc48542977..32851ffffb 100644 --- a/mongo/client_encryption.go +++ b/mongo/client_encryption.go @@ -82,7 +82,7 @@ func NewClientEncryption(keyVaultClient *Client, opts ...options.Lister[options. // It returns the created collection and the encrypted fields document used to create it. func (ce *ClientEncryption) CreateEncryptedCollection(ctx context.Context, db *Database, coll string, createOpts options.Lister[options.CreateCollectionOptions], - kmsProvider string, masterKey interface{}) (*Collection, bson.M, error) { + kmsProvider string, masterKey any) (*Collection, bson.M, error) { if ce.closed { return nil, nil, ErrClientDisconnected } @@ -273,7 +273,7 @@ func (ce *ClientEncryption) Encrypt( // {$and: [{$gt: [, ]}, {$lt: [, ]}] // $gt may also be $gte. $lt may also be $lte. // Only supported for queryType "range" -func (ce *ClientEncryption) EncryptExpression(ctx context.Context, expr interface{}, result interface{}, opts ...options.Lister[options.EncryptOptions]) error { +func (ce *ClientEncryption) EncryptExpression(ctx context.Context, expr any, result any, opts ...options.Lister[options.EncryptOptions]) error { if ce.closed { return ErrClientDisconnected } @@ -444,7 +444,7 @@ func setRewrapManyDataKeyWriteModels(rewrappedDocuments []bsoncore.Document, wri // libmongocrypt 1.5.2 is required. An error is returned if the detected version of libmongocrypt is less than 1.5.2. func (ce *ClientEncryption) RewrapManyDataKey( ctx context.Context, - filter interface{}, + filter any, opts ...options.Lister[options.RewrapManyDataKeyOptions], ) (*RewrapManyDataKeyResult, error) { // libmongocrypt versions 1.5.0 and 1.5.1 have a severe bug in RewrapManyDataKey. diff --git a/mongo/client_examples_test.go b/mongo/client_examples_test.go index 4ba8aebbf7..971fc74f08 100644 --- a/mongo/client_examples_test.go +++ b/mongo/client_examples_test.go @@ -449,8 +449,8 @@ func ExampleConnect_bSONOptions() { // Define a struct that contains a map and a slice and uses "json" struct // tags to specify field names. type myDocument struct { - MyMap map[string]interface{} `json:"a"` - MySlice []string `json:"b"` + MyMap map[string]any `json:"a"` + MySlice []string `json:"b"` } // Insert an instance of the struct with all empty fields. Expect the diff --git a/mongo/client_side_encryption_examples_test.go b/mongo/client_side_encryption_examples_test.go index 0ca9e2a5aa..8c8d6599ce 100644 --- a/mongo/client_side_encryption_examples_test.go +++ b/mongo/client_side_encryption_examples_test.go @@ -24,7 +24,7 @@ func Example_clientSideEncryption() { if _, err := rand.Read(localKey); err != nil { log.Panic(err) } - kmsProviders := map[string]map[string]interface{}{ + kmsProviders := map[string]map[string]any{ "local": { "key": localKey, }, @@ -71,7 +71,7 @@ func Example_clientSideEncryptionCreateKey() { uri := "mongodb://localhost:27017" // kmsProviders would have to be populated with the correct KMS provider // information before it's used. - var kmsProviders map[string]map[string]interface{} + var kmsProviders map[string]map[string]any // Create Client and ClientEncryption clientEncryptionOpts := options.ClientEncryption(). @@ -128,7 +128,7 @@ func Example_clientSideEncryptionCreateKey() { // Configure a Client with auto encryption using the new schema dbName := "test" collName := "coll" - schemaMap := map[string]interface{}{ + schemaMap := map[string]any{ dbName + "." + collName: schemaDoc, } autoEncryptionOpts := options.AutoEncryption(). @@ -154,7 +154,7 @@ func Example_explictEncryption() { // localMasterKey must be the same master key that was used to create the // encryption key. var localMasterKey []byte - kmsProviders := map[string]map[string]interface{}{ + kmsProviders := map[string]map[string]any{ "local": { "key": localMasterKey, }, @@ -268,7 +268,7 @@ func Example_explictEncryptionWithAutomaticDecryption() { // localMasterKey must be the same master key that was used to create the // encryption key. var localMasterKey []byte - kmsProviders := map[string]map[string]interface{}{ + kmsProviders := map[string]map[string]any{ "local": { "key": localMasterKey, }, diff --git a/mongo/client_test.go b/mongo/client_test.go index 204aa52a1e..7e832a15c8 100644 --- a/mongo/client_test.go +++ b/mongo/client_test.go @@ -470,7 +470,7 @@ func TestClient(t *testing.T) { } for _, tc := range testCases { t.Run(tc.description, func(t *testing.T) { - extraOptions := map[string]interface{}{ + extraOptions := map[string]any{ // Set a mongocryptd path that does not exist. If Connect() attempts to start // mongocryptd, it will cause an error. "mongocryptdPath": "/does/not/exist", @@ -489,7 +489,7 @@ func TestClient(t *testing.T) { _, err := newClient(options.Client(). SetAutoEncryptionOptions(options.AutoEncryption(). - SetKmsProviders(map[string]map[string]interface{}{ + SetKmsProviders(map[string]map[string]any{ "local": {"key": make([]byte, 96)}, }). SetExtraOptions(extraOptions))) diff --git a/mongo/collection.go b/mongo/collection.go index 80c15c48d0..9da9240c5e 100644 --- a/mongo/collection.go +++ b/mongo/collection.go @@ -47,7 +47,7 @@ type Collection struct { // aggregateParams is used to store information to configure an Aggregate operation. type aggregateParams struct { ctx context.Context - pipeline interface{} + pipeline any client *Client bsonOpts *options.BSONOptions registry *bson.Registry @@ -259,15 +259,15 @@ func (coll *Collection) BulkWrite(ctx context.Context, models []WriteModel, func (coll *Collection) insert( ctx context.Context, - documents []interface{}, + documents []any, opts ...options.Lister[options.InsertManyOptions], -) ([]interface{}, error) { +) ([]any, error) { if ctx == nil { ctx = context.Background() } - result := make([]interface{}, len(documents)) + result := make([]any, len(documents)) docs := make([]bsoncore.Document, len(documents)) for i, doc := range documents { @@ -371,7 +371,7 @@ func (coll *Collection) insert( // The opts parameter can be used to specify options for the operation (see the options.InsertOneOptions documentation.) // // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/insert/. -func (coll *Collection) InsertOne(ctx context.Context, document interface{}, +func (coll *Collection) InsertOne(ctx context.Context, document any, opts ...options.Lister[options.InsertOneOptions]) (*InsertOneResult, error) { args, err := mongoutil.NewOptions(opts...) @@ -393,7 +393,7 @@ func (coll *Collection) InsertOne(ctx context.Context, document interface{}, return nil }) } - res, err := coll.insert(ctx, []interface{}{document}, imOpts) + res, err := coll.insert(ctx, []any{document}, imOpts) rr, err := processWriteError(err) if rr&rrOne == 0 && rr.isAcknowledged() { @@ -419,7 +419,7 @@ func (coll *Collection) InsertOne(ctx context.Context, document interface{}, // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/insert/. func (coll *Collection) InsertMany( ctx context.Context, - documents interface{}, + documents any, opts ...options.Lister[options.InsertManyOptions], ) (*InsertManyResult, error) { @@ -431,7 +431,7 @@ func (coll *Collection) InsertMany( return nil, fmt.Errorf("invalid documents: %w", ErrEmptySlice) } - docSlice := make([]interface{}, 0, dv.Len()) + docSlice := make([]any, 0, dv.Len()) for i := 0; i < dv.Len(); i++ { docSlice = append(docSlice, dv.Index(i).Interface()) } @@ -469,7 +469,7 @@ func (coll *Collection) InsertMany( func (coll *Collection) delete( ctx context.Context, - filter interface{}, + filter any, deleteOne bool, expectedRr returnResult, args *options.DeleteManyOptions, @@ -586,7 +586,7 @@ func (coll *Collection) delete( // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/delete/. func (coll *Collection) DeleteOne( ctx context.Context, - filter interface{}, + filter any, opts ...options.Lister[options.DeleteOneOptions], ) (*DeleteResult, error) { args, err := mongoutil.NewOptions[options.DeleteOneOptions](opts...) @@ -616,7 +616,7 @@ func (coll *Collection) DeleteOne( // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/delete/. func (coll *Collection) DeleteMany( ctx context.Context, - filter interface{}, + filter any, opts ...options.Lister[options.DeleteManyOptions], ) (*DeleteResult, error) { args, err := mongoutil.NewOptions[options.DeleteManyOptions](opts...) @@ -630,11 +630,11 @@ func (coll *Collection) DeleteMany( func (coll *Collection) updateOrReplace( ctx context.Context, filter bsoncore.Document, - update interface{}, + update any, multi bool, expectedRr returnResult, checkDollarKey bool, - sort interface{}, + sort any, args *options.UpdateManyOptions, ) (*UpdateResult, error) { @@ -753,8 +753,8 @@ func (coll *Collection) updateOrReplace( // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/update/. func (coll *Collection) UpdateByID( ctx context.Context, - id interface{}, - update interface{}, + id any, + update any, opts ...options.Lister[options.UpdateOneOptions], ) (*UpdateResult, error) { if id == nil { @@ -779,8 +779,8 @@ func (coll *Collection) UpdateByID( // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/update/. func (coll *Collection) UpdateOne( ctx context.Context, - filter interface{}, - update interface{}, + filter any, + update any, opts ...options.Lister[options.UpdateOneOptions], ) (*UpdateResult, error) { if ctx == nil { @@ -825,8 +825,8 @@ func (coll *Collection) UpdateOne( // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/update/. func (coll *Collection) UpdateMany( ctx context.Context, - filter interface{}, - update interface{}, + filter any, + update any, opts ...options.Lister[options.UpdateManyOptions], ) (*UpdateResult, error) { if ctx == nil { @@ -861,8 +861,8 @@ func (coll *Collection) UpdateMany( // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/update/. func (coll *Collection) ReplaceOne( ctx context.Context, - filter interface{}, - replacement interface{}, + filter any, + replacement any, opts ...options.Lister[options.ReplaceOptions], ) (*UpdateResult, error) { if ctx == nil { @@ -914,7 +914,7 @@ func (coll *Collection) ReplaceOne( // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/aggregate/. func (coll *Collection) Aggregate( ctx context.Context, - pipeline interface{}, + pipeline any, opts ...options.Lister[options.AggregateOptions], ) (*Cursor, error) { a := aggregateParams{ @@ -1104,7 +1104,7 @@ func aggregate(a aggregateParams, opts ...options.Lister[options.AggregateOption // result in a full collection scan. // // The opts parameter can be used to specify options for the operation (see the options.CountOptions documentation). -func (coll *Collection) CountDocuments(ctx context.Context, filter interface{}, +func (coll *Collection) CountDocuments(ctx context.Context, filter any, opts ...options.Lister[options.CountOptions]) (int64, error) { if ctx == nil { ctx = context.Background() @@ -1275,7 +1275,7 @@ func (coll *Collection) EstimatedDocumentCount( func (coll *Collection) Distinct( ctx context.Context, fieldName string, - filter interface{}, + filter any, opts ...options.Lister[options.DistinctOptions], ) *DistinctResult { if ctx == nil { @@ -1378,7 +1378,7 @@ func (coll *Collection) Distinct( // The opts parameter can be used to specify options for the operation (see the options.FindOptions documentation). // // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/find/. -func (coll *Collection) Find(ctx context.Context, filter interface{}, +func (coll *Collection) Find(ctx context.Context, filter any, opts ...options.Lister[options.FindOptions]) (*Cursor, error) { args, err := mongoutil.NewOptions(opts...) if err != nil { @@ -1394,7 +1394,7 @@ func (coll *Collection) Find(ctx context.Context, filter interface{}, func (coll *Collection) find( ctx context.Context, - filter interface{}, + filter any, omitMaxTimeMS bool, args *options.FindOptions, ) (cur *Cursor, err error) { @@ -1600,7 +1600,7 @@ func newFindArgsFromFindOneArgs(args *options.FindOneOptions) *options.FindOptio // The opts parameter can be used to specify options for this operation (see the options.FindOneOptions documentation). // // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/find/. -func (coll *Collection) FindOne(ctx context.Context, filter interface{}, +func (coll *Collection) FindOne(ctx context.Context, filter any, opts ...options.Lister[options.FindOneOptions]) *SingleResult { if ctx == nil { @@ -1691,7 +1691,7 @@ func (coll *Collection) findAndModify(ctx context.Context, op *operation.FindAnd // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/findAndModify/. func (coll *Collection) FindOneAndDelete( ctx context.Context, - filter interface{}, + filter any, opts ...options.Lister[options.FindOneAndDeleteOptions]) *SingleResult { f, err := marshal(filter, coll.bsonOpts, coll.registry) @@ -1774,8 +1774,8 @@ func (coll *Collection) FindOneAndDelete( // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/findAndModify/. func (coll *Collection) FindOneAndReplace( ctx context.Context, - filter interface{}, - replacement interface{}, + filter any, + replacement any, opts ...options.Lister[options.FindOneAndReplaceOptions], ) *SingleResult { @@ -1877,8 +1877,8 @@ func (coll *Collection) FindOneAndReplace( // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/findAndModify/. func (coll *Collection) FindOneAndUpdate( ctx context.Context, - filter interface{}, - update interface{}, + filter any, + update any, opts ...options.Lister[options.FindOneAndUpdateOptions]) *SingleResult { if ctx == nil { @@ -1987,7 +1987,7 @@ func (coll *Collection) FindOneAndUpdate( // // The opts parameter can be used to specify options for change stream creation (see the options.ChangeStreamOptions // documentation). -func (coll *Collection) Watch(ctx context.Context, pipeline interface{}, +func (coll *Collection) Watch(ctx context.Context, pipeline any, opts ...options.Lister[options.ChangeStreamOptions]) (*ChangeStream, error) { csConfig := changeStreamConfig{ @@ -2048,7 +2048,7 @@ func (coll *Collection) Drop(ctx context.Context, opts ...options.Lister[options } // dropEncryptedCollection drops a collection with EncryptedFields. -func (coll *Collection) dropEncryptedCollection(ctx context.Context, ef interface{}) error { +func (coll *Collection) dropEncryptedCollection(ctx context.Context, ef any) error { efBSON, err := marshal(ef, coll.bsonOpts, coll.registry) if err != nil { return fmt.Errorf("error transforming document: %w", err) @@ -2241,7 +2241,7 @@ func makeOutputAggregateSelector( // isUnorderedMap returns true if val is a map with more than 1 element. It is typically used to // check for unordered Go values that are used in nested command documents where different field // orders mean different things. Examples are the "sort" and "hint" fields. -func isUnorderedMap(val interface{}) bool { +func isUnorderedMap(val any) bool { refValue := reflect.ValueOf(val) return refValue.Kind() == reflect.Map && refValue.Len() > 1 } diff --git a/mongo/collection_test.go b/mongo/collection_test.go index 23a1209e11..e20d97dd61 100644 --- a/mongo/collection_test.go +++ b/mongo/collection_test.go @@ -95,7 +95,7 @@ func TestCollection(t *testing.T) { _, err = coll.InsertOne(bgCtx, doc) assert.Equal(t, ErrClientDisconnected, err, "expected error %v, got %v", ErrClientDisconnected, err) - _, err = coll.InsertMany(bgCtx, []interface{}{doc}) + _, err = coll.InsertMany(bgCtx, []any{doc}) assert.Equal(t, ErrClientDisconnected, err, "expected error %v, got %v", ErrClientDisconnected, err) _, err = coll.DeleteOne(bgCtx, doc) @@ -155,7 +155,7 @@ func TestCollection(t *testing.T) { _, err = coll.InsertMany(bgCtx, nil) assert.True(t, errors.Is(err, ErrNotSlice), "expected error %v, got %v", ErrNotSlice, err) - _, err = coll.InsertMany(bgCtx, []interface{}{}) + _, err = coll.InsertMany(bgCtx, []any{}) assert.True(t, errors.Is(err, ErrEmptySlice), "expected error %v, got %v", ErrEmptySlice, err) _, err = coll.InsertMany(bgCtx, "x") diff --git a/mongo/crud_examples_test.go b/mongo/crud_examples_test.go index ff61f19f3d..10619b5cd1 100644 --- a/mongo/crud_examples_test.go +++ b/mongo/crud_examples_test.go @@ -493,7 +493,7 @@ func ExampleCollection_InsertMany() { // Insert documents {name: "Alice"} and {name: "Bob"}. // Set the Ordered option to false to allow both operations to happen even // if one of them errors. - docs := []interface{}{ + docs := []any{ bson.D{{"name", "Alice"}}, bson.D{{"name", "Bob"}}, } @@ -761,7 +761,7 @@ func ExampleClient_StartSession_withTransaction() { txnOpts.SetReadPreference(readpref.PrimaryPreferred()) result, err := sess.WithTransaction( context.TODO(), - func(ctx context.Context) (interface{}, error) { + func(ctx context.Context) (any, error) { // Use the context.Context as the Context parameter for // InsertOne and FindOne so both operations are run in the same // transaction. @@ -1106,7 +1106,7 @@ func ExampleCollection_Find_primitiveRegex() { // Create a slice of documents to insert. We will lookup a subset of // these documents using regex. - toInsert := []interface{}{ + toInsert := []any{ Pet{Type: "cat", Name: "Mo"}, Pet{Type: "dog", Name: "Loki"}, } @@ -1147,7 +1147,7 @@ func ExampleCollection_Find_regex() { // Create a slice of documents to insert. We will lookup a subset of // these documents using regex. - toInsert := []interface{}{ + toInsert := []any{ Pet{Type: "cat", Name: "Mo"}, Pet{Type: "dog", Name: "Loki"}, } diff --git a/mongo/cursor.go b/mongo/cursor.go index 583cbd00df..743622e88b 100644 --- a/mongo/cursor.go +++ b/mongo/cursor.go @@ -86,7 +86,7 @@ func newEmptyCursor() *Cursor { // bson.NewRegistry() will be used. // // The documents parameter must be a slice of documents. The slice may be nil or empty, but all elements must be non-nil. -func NewCursorFromDocuments(documents []interface{}, preloadedErr error, registry *bson.Registry) (*Cursor, error) { +func NewCursorFromDocuments(documents []any, preloadedErr error, registry *bson.Registry) (*Cursor, error) { if registry == nil { registry = defaultRegistry } @@ -303,7 +303,7 @@ func getDecoder( // Decode will unmarshal the current 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 (c *Cursor) Decode(val interface{}) error { +func (c *Cursor) Decode(val any) error { dec := getDecoder(c.Current, c.bsonOpts, c.registry) return dec.Decode(val) @@ -325,7 +325,7 @@ func (c *Cursor) Close(ctx context.Context) error { // cursor has been iterated, any previously iterated documents will not be included in results. // // This method requires driver version >= 1.1.0. -func (c *Cursor) All(ctx context.Context, results interface{}) error { +func (c *Cursor) All(ctx context.Context, results any) error { resultsVal := reflect.ValueOf(results) if resultsVal.Kind() != reflect.Ptr { return fmt.Errorf("results argument must be a pointer to a slice, but was a %s", resultsVal.Kind()) @@ -434,7 +434,7 @@ func (c *Cursor) SetMaxAwaitTime(dur time.Duration) { // SetComment will set a user-configurable comment that can be used to identify // the operation in server logs. -func (c *Cursor) SetComment(comment interface{}) { +func (c *Cursor) SetComment(comment any) { c.bc.SetComment(comment) } diff --git a/mongo/cursor_test.go b/mongo/cursor_test.go index 4573c9f9ac..283ca373f3 100644 --- a/mongo/cursor_test.go +++ b/mongo/cursor_test.go @@ -99,7 +99,7 @@ func (tbc *testBatchCursor) Close(context.Context) error { } func (tbc *testBatchCursor) SetBatchSize(int32) {} -func (tbc *testBatchCursor) SetComment(interface{}) {} +func (tbc *testBatchCursor) SetComment(any) {} func (tbc *testBatchCursor) SetMaxAwaitTime(time.Duration) {} func (tbc *testBatchCursor) MaxAwaitTime() *time.Duration { return nil } @@ -204,7 +204,7 @@ func TestCursor(t *testing.T) { }) t.Run("does not error given interface as parameter", func(t *testing.T) { - var docs interface{} = []bson.D{} + var docs any = []bson.D{} cursor, err := newCursor(newTestBatchCursor(1, 5), nil, nil) require.NoError(t, err, "newCursor error: %v", err) @@ -214,7 +214,7 @@ func TestCursor(t *testing.T) { assert.Len(t, docs.([]bson.D), 5, "expected 5 documents, got %v", len(docs.([]bson.D))) }) t.Run("errors when not given pointer to slice", func(t *testing.T) { - var docs interface{} = "test" + var docs any = "test" cursor, err := newCursor(newTestBatchCursor(1, 5), nil, nil) require.NoError(t, err, "newCursor error: %v", err) @@ -249,7 +249,7 @@ func TestCursor(t *testing.T) { func TestNewCursorFromDocuments(t *testing.T) { // Mock documents returned by Find in a Cursor. t.Run("mock Find", func(t *testing.T) { - findResult := []interface{}{ + findResult := []any{ bson.D{{"_id", 0}, {"foo", "bar"}}, bson.D{{"_id", 1}, {"baz", "qux"}}, bson.D{{"_id", 2}, {"quux", "quuz"}}, @@ -285,7 +285,7 @@ func TestNewCursorFromDocuments(t *testing.T) { // Mock an error in a Cursor. t.Run("mock Find with error", func(t *testing.T) { mockErr := fmt.Errorf("mock error") - findResult := []interface{}{bson.D{{"_id", 0}, {"foo", "bar"}}} + findResult := []any{bson.D{{"_id", 0}, {"foo", "bar"}}} cur, err := NewCursorFromDocuments(findResult, mockErr, nil) require.NoError(t, err, "NewCursorFromDocuments error: %v", err) @@ -334,7 +334,7 @@ func TestGetDecoder(t *testing.T) { func BenchmarkNewCursorFromDocuments(b *testing.B) { // Prepare sample data - documents := []interface{}{ + documents := []any{ bson.D{{"_id", 0}, {"foo", "bar"}}, bson.D{{"_id", 1}, {"baz", "qux"}}, bson.D{{"_id", 2}, {"quux", "quuz"}}, diff --git a/mongo/database.go b/mongo/database.go index 8476aeb201..0d2690c4bd 100644 --- a/mongo/database.go +++ b/mongo/database.go @@ -132,7 +132,7 @@ func (db *Database) Collection(name string, opts ...options.Lister[options.Colle // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/aggregate/. func (db *Database) Aggregate( ctx context.Context, - pipeline interface{}, + pipeline any, opts ...options.Lister[options.AggregateOptions], ) (*Cursor, error) { a := aggregateParams{ @@ -154,7 +154,7 @@ func (db *Database) Aggregate( func (db *Database) processRunCommand( ctx context.Context, - cmd interface{}, + cmd any, cursorCommand bool, opts ...options.Lister[options.RunCmdOptions], ) (*operation.Command, *session.Client, error) { @@ -237,7 +237,7 @@ func (db *Database) processRunCommand( // - maxTimeMS when Timeout is set on the Client func (db *Database) RunCommand( ctx context.Context, - runCommand interface{}, + runCommand any, opts ...options.Lister[options.RunCmdOptions], ) *SingleResult { if ctx == nil { @@ -279,7 +279,7 @@ func (db *Database) RunCommand( // - maxTimeMS when Timeout is set on the Client func (db *Database) RunCommandCursor( ctx context.Context, - runCommand interface{}, + runCommand any, opts ...options.Lister[options.RunCmdOptions], ) (*Cursor, error) { if ctx == nil { @@ -366,7 +366,7 @@ func (db *Database) Drop(ctx context.Context) error { // For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/listCollections/. func (db *Database) ListCollectionSpecifications( ctx context.Context, - filter interface{}, + filter any, opts ...options.Lister[options.ListCollectionsOptions], ) ([]CollectionSpecification, error) { cursor, err := db.ListCollections(ctx, filter, opts...) @@ -429,7 +429,7 @@ func (db *Database) ListCollectionSpecifications( // MongoDB version 2.6. func (db *Database) ListCollections( ctx context.Context, - filter interface{}, + filter any, opts ...options.Lister[options.ListCollectionsOptions], ) (*Cursor, error) { if ctx == nil { @@ -531,7 +531,7 @@ func (db *Database) ListCollections( // MongoDB version 2.6. func (db *Database) ListCollectionNames( ctx context.Context, - filter interface{}, + filter any, opts ...options.Lister[options.ListCollectionsOptions], ) ([]string, error) { opts = append(opts, options.ListCollections().SetNameOnly(true)) @@ -575,7 +575,7 @@ func (db *Database) ListCollectionNames( // // The opts parameter can be used to specify options for change stream creation (see the options.ChangeStreamOptions // documentation). -func (db *Database) Watch(ctx context.Context, pipeline interface{}, +func (db *Database) Watch(ctx context.Context, pipeline any, opts ...options.Lister[options.ChangeStreamOptions]) (*ChangeStream, error) { csConfig := changeStreamConfig{ @@ -622,7 +622,7 @@ func (db *Database) CreateCollection(ctx context.Context, name string, opts ...o // getEncryptedFieldsFromServer tries to get an "encryptedFields" document associated with collectionName by running the "listCollections" command. // Returns nil and no error if the listCollections command succeeds, but "encryptedFields" is not present. -func (db *Database) getEncryptedFieldsFromServer(ctx context.Context, collectionName string) (interface{}, error) { +func (db *Database) getEncryptedFieldsFromServer(ctx context.Context, collectionName string) (any, error) { // Check if collection has an EncryptedFields configured server-side. collSpecs, err := db.ListCollectionSpecifications(ctx, bson.D{{"name", collectionName}}) if err != nil { @@ -652,7 +652,7 @@ func (db *Database) getEncryptedFieldsFromServer(ctx context.Context, collection // getEncryptedFieldsFromMap tries to get an "encryptedFields" document associated with collectionName by checking the client EncryptedFieldsMap. // Returns nil and no error if an EncryptedFieldsMap is not configured, or does not contain an entry for collectionName. -func (db *Database) getEncryptedFieldsFromMap(collectionName string) interface{} { +func (db *Database) getEncryptedFieldsFromMap(collectionName string) any { // Check the EncryptedFieldsMap efMap := db.client.encryptedFieldsMap if efMap == nil { @@ -672,7 +672,7 @@ func (db *Database) getEncryptedFieldsFromMap(collectionName string) interface{} func (db *Database) createCollectionWithEncryptedFields( ctx context.Context, name string, - ef interface{}, + ef any, opts ...options.Lister[options.CreateCollectionOptions], ) error { efBSON, err := marshal(ef, db.bsonOpts, db.registry) @@ -896,7 +896,7 @@ func (db *Database) createCollectionOperation( // // See https://www.mongodb.com/docs/manual/core/views/ for more information // about views. -func (db *Database) CreateView(ctx context.Context, viewName, viewOn string, pipeline interface{}, +func (db *Database) CreateView(ctx context.Context, viewName, viewOn string, pipeline any, opts ...options.Lister[options.CreateViewOptions]) error { pipelineArray, _, err := marshalAggregatePipeline(pipeline, db.bsonOpts, db.registry) diff --git a/mongo/doc.go b/mongo/doc.go index 21e06b06d3..3756d58f11 100644 --- a/mongo/doc.go +++ b/mongo/doc.go @@ -73,8 +73,8 @@ // if err != nil { return err } // // do something with result... // -// All Client, Collection, and Database methods that take parameters of type interface{} -// will return ErrNilDocument if nil is passed in for an interface{}. +// All Client, Collection, and Database methods that take parameters of type any +// will return ErrNilDocument if nil is passed in for an any. // // Additional examples can be found under the examples directory in the driver's repository and // on the MongoDB website. diff --git a/mongo/errors.go b/mongo/errors.go index a353dbe707..234445ab86 100644 --- a/mongo/errors.go +++ b/mongo/errors.go @@ -238,7 +238,7 @@ func IsNetworkError(err error) bool { // MarshalError is returned when attempting to marshal a value into a document // results in an error. type MarshalError struct { - Value interface{} + Value any Err error // If wrappedMsgOnly is true, Error() only returns the error message from diff --git a/mongo/gridfs_bucket.go b/mongo/gridfs_bucket.go index 8bb418ad18..7423077029 100644 --- a/mongo/gridfs_bucket.go +++ b/mongo/gridfs_bucket.go @@ -80,7 +80,7 @@ func (b *GridFSBucket) OpenUploadStream( // client-level timeout will be used to cap the lifetime of the stream. func (b *GridFSBucket) OpenUploadStreamWithID( ctx context.Context, - fileID interface{}, + fileID any, filename string, opts ...options.Lister[options.GridFSUploadOptions], ) (*GridFSUploadStream, error) { @@ -129,7 +129,7 @@ func (b *GridFSBucket) UploadFromStream( // client-level timeout will be used to cap the lifetime of the stream. func (b *GridFSBucket) UploadFromStreamWithID( ctx context.Context, - fileID interface{}, + fileID any, filename string, source io.Reader, opts ...options.Lister[options.GridFSUploadOptions], @@ -170,7 +170,7 @@ func (b *GridFSBucket) UploadFromStreamWithID( // The context provided to this method controls the entire lifetime of an // upload stream io.Writer. If the context does set a deadline, then the // client-level timeout will be used to cap the lifetime of the stream. -func (b *GridFSBucket) OpenDownloadStream(ctx context.Context, fileID interface{}) (*GridFSDownloadStream, error) { +func (b *GridFSBucket) OpenDownloadStream(ctx context.Context, fileID any) (*GridFSDownloadStream, error) { return b.openDownloadStream(ctx, bson.D{{"_id", fileID}}) } @@ -185,7 +185,7 @@ func (b *GridFSBucket) OpenDownloadStream(ctx context.Context, fileID interface{ // The context provided to this method controls the entire lifetime of an // upload stream io.Writer. If the context does set a deadline, then the // client-level timeout will be used to cap the lifetime of the stream. -func (b *GridFSBucket) DownloadToStream(ctx context.Context, fileID interface{}, stream io.Writer) (int64, error) { +func (b *GridFSBucket) DownloadToStream(ctx context.Context, fileID any, stream io.Writer) (int64, error) { ds, err := b.OpenDownloadStream(ctx, fileID) if err != nil { return 0, err @@ -254,7 +254,7 @@ func (b *GridFSBucket) DownloadToStreamByName( // Delete deletes all chunks and metadata associated with the file with the // given file ID and runs the underlying delete operations with the provided // context. -func (b *GridFSBucket) Delete(ctx context.Context, fileID interface{}) error { +func (b *GridFSBucket) Delete(ctx context.Context, fileID any) error { ctx, cancel := csot.WithTimeout(ctx, b.db.client.timeout) defer cancel() @@ -274,7 +274,7 @@ func (b *GridFSBucket) Delete(ctx context.Context, fileID interface{}) error { // runs the underlying find query with the provided context. func (b *GridFSBucket) Find( ctx context.Context, - filter interface{}, + filter any, opts ...options.Lister[options.GridFSFindOptions], ) (*Cursor, error) { args, err := mongoutil.NewOptions[options.GridFSFindOptions](opts...) @@ -306,7 +306,7 @@ func (b *GridFSBucket) Find( } // Rename renames the stored file with the specified file ID. -func (b *GridFSBucket) Rename(ctx context.Context, fileID interface{}, newFilename string) error { +func (b *GridFSBucket) Rename(ctx context.Context, fileID any, newFilename string) error { res, err := b.filesColl.UpdateOne(ctx, bson.D{{"_id", fileID}}, bson.D{{"$set", bson.D{{"filename", newFilename}}}}, @@ -348,7 +348,7 @@ func (b *GridFSBucket) GetChunksCollection() *Collection { func (b *GridFSBucket) openDownloadStream( ctx context.Context, - filter interface{}, + filter any, opts ...options.Lister[options.FindOneOptions], ) (*GridFSDownloadStream, error) { ctx, cancel := csot.WithTimeout(ctx, b.db.client.timeout) @@ -398,12 +398,12 @@ func (b *GridFSBucket) downloadToStream(ds *GridFSDownloadStream, stream io.Writ return copied, ds.Close() } -func (b *GridFSBucket) deleteChunks(ctx context.Context, fileID interface{}) error { +func (b *GridFSBucket) deleteChunks(ctx context.Context, fileID any) error { _, err := b.chunksColl.DeleteMany(ctx, bson.D{{"files_id", fileID}}) return err } -func (b *GridFSBucket) findChunks(ctx context.Context, fileID interface{}) (*Cursor, error) { +func (b *GridFSBucket) findChunks(ctx context.Context, fileID any) (*Cursor, error) { chunksCursor, err := b.chunksColl.Find(ctx, bson.D{{"files_id", fileID}}, options.Find().SetSort(bson.D{{"n", 1}})) // sort by chunk index diff --git a/mongo/gridfs_bucket_test.go b/mongo/gridfs_bucket_test.go index 7b01fff1c8..beadbec365 100644 --- a/mongo/gridfs_bucket_test.go +++ b/mongo/gridfs_bucket_test.go @@ -19,7 +19,7 @@ import ( func TestBucket_openDownloadStream(t *testing.T) { tests := []struct { name string - filter interface{} + filter any err error }{ { diff --git a/mongo/gridfs_download_stream.go b/mongo/gridfs_download_stream.go index 33174854cd..c7967b748f 100644 --- a/mongo/gridfs_download_stream.go +++ b/mongo/gridfs_download_stream.go @@ -53,7 +53,7 @@ type GridFSDownloadStream struct { type GridFSFile struct { // ID is the file's ID. This will match the file ID specified when uploading the file. If an upload helper that // does not require a file ID was used, this field will be a bson.ObjectID. - ID interface{} + ID any // Length is the length of this file in bytes. Length int64 @@ -79,12 +79,12 @@ var _ bson.Unmarshaler = &GridFSFile{} // files collection and can be transformed into a File instance. This type // exists to avoid adding BSON struct tags to the exported File type. type findFileResponse struct { - ID interface{} `bson:"_id"` - Length int64 `bson:"length"` - ChunkSize int32 `bson:"chunkSize"` - UploadDate time.Time `bson:"uploadDate"` - Name string `bson:"filename"` - Metadata bson.Raw `bson:"metadata"` + ID any `bson:"_id"` + Length int64 `bson:"length"` + ChunkSize int32 `bson:"chunkSize"` + UploadDate time.Time `bson:"uploadDate"` + Name string `bson:"filename"` + Metadata bson.Raw `bson:"metadata"` } func newFileFromResponse(resp findFileResponse) *GridFSFile { diff --git a/mongo/gridfs_upload_stream.go b/mongo/gridfs_upload_stream.go index c1f9277412..ba7883d978 100644 --- a/mongo/gridfs_upload_stream.go +++ b/mongo/gridfs_upload_stream.go @@ -29,7 +29,7 @@ var ErrStreamClosed = errors.New("stream is closed or aborted") // metadata. type GridFSUploadStream struct { *upload // chunk size and metadata - FileID interface{} + FileID any chunkIndex int chunksColl *Collection // collection to store file chunks @@ -48,7 +48,7 @@ func newUploadStream( ctx context.Context, cancel context.CancelFunc, up *upload, - fileID interface{}, + fileID any, filename string, chunks, files *Collection, ) *GridFSUploadStream { @@ -150,7 +150,7 @@ func (us *GridFSUploadStream) uploadChunks(ctx context.Context, uploadPartial bo numChunks = int(math.Floor(chunks)) } - docs := make([]interface{}, numChunks) + docs := make([]any, numChunks) begChunkIndex := us.chunkIndex for i := 0; i < us.bufferIndex; i += int(us.chunkSize) { diff --git a/mongo/index_view.go b/mongo/index_view.go index 7198c4cc43..4e692fbc5c 100644 --- a/mongo/index_view.go +++ b/mongo/index_view.go @@ -45,7 +45,7 @@ type IndexModel struct { // A document describing which keys should be used for the index. It cannot be nil. This must be an order-preserving // type such as bson.D. Map types such as bson.M are not valid. See https://www.mongodb.com/docs/manual/indexes/#indexes // for examples of valid documents. - Keys interface{} + Keys any // The options to use to create the index. Options *options.IndexOptionsBuilder @@ -465,7 +465,7 @@ func (iv IndexView) DropOne( // DropWithKey drops a collection index by key using the dropIndexes operation. // // This function is useful to drop an index using its key specification instead of its name. -func (iv IndexView) DropWithKey(ctx context.Context, keySpecDocument interface{}, opts ...options.Lister[options.DropIndexesOptions]) error { +func (iv IndexView) DropWithKey(ctx context.Context, keySpecDocument any, opts ...options.Lister[options.DropIndexesOptions]) error { doc, err := marshal(keySpecDocument, iv.coll.bsonOpts, iv.coll.registry) if err != nil { return err diff --git a/mongo/mongo.go b/mongo/mongo.go index c12e8ba4e4..703115fdc7 100644 --- a/mongo/mongo.go +++ b/mongo/mongo.go @@ -103,7 +103,7 @@ func newEncoderFn(opts *options.BSONOptions, registry *bson.Registry) codecutil. // If bsonOpts and registry are specified, the encoder is configured with the requested behaviors. // If they are nil, the default behaviors are used. func marshal( - val interface{}, + val any, bsonOpts *options.BSONOptions, registry *bson.Registry, ) (bsoncore.Document, error) { @@ -140,17 +140,17 @@ func ensureID( oid bson.ObjectID, bsonOpts *options.BSONOptions, reg *bson.Registry, -) (bsoncore.Document, interface{}, error) { +) (bsoncore.Document, any, error) { if reg == nil { reg = defaultRegistry } // Try to find the "_id" element. If it exists, try to unmarshal just the - // "_id" field as an interface{} and return it along with the unmodified + // "_id" field as an any and return it along with the unmodified // BSON document. if _, err := doc.LookupErr("_id"); err == nil { var id struct { - ID interface{} `bson:"_id"` + ID any `bson:"_id"` } dec := getDecoder(doc, bsonOpts, reg) err = dec.Decode(&id) @@ -205,7 +205,7 @@ func ensureNoDollarKey(doc bsoncore.Document) error { } func marshalAggregatePipeline( - pipeline interface{}, + pipeline any, bsonOpts *options.BSONOptions, registry *bson.Registry, ) (bsoncore.Document, bool, error) { @@ -293,7 +293,7 @@ func marshalAggregatePipeline( } func marshalUpdateValue( - update interface{}, + update any, bsonOpts *options.BSONOptions, registry *bson.Registry, dollarKeysAllowed bool, @@ -383,7 +383,7 @@ func marshalUpdateValue( } func marshalValue( - val interface{}, + val any, bsonOpts *options.BSONOptions, registry *bson.Registry, ) (bsoncore.Value, error) { @@ -392,7 +392,7 @@ func marshalValue( // Build the aggregation pipeline for the CountDocument command. func countDocumentsAggregatePipeline( - filter interface{}, + filter any, encOpts *options.BSONOptions, registry *bson.Registry, args *options.CountOptions, diff --git a/mongo/mongo_test.go b/mongo/mongo_test.go index 96be905cb5..f0cb6125dc 100644 --- a/mongo/mongo_test.go +++ b/mongo/mongo_test.go @@ -31,7 +31,7 @@ func TestEnsureID(t *testing.T) { doc bsoncore.Document oid bson.ObjectID want bsoncore.Document - wantID interface{} + wantID any }{ { description: "missing _id should be first element", @@ -195,7 +195,7 @@ func TestMarshalAggregatePipeline(t *testing.T) { testCases := []struct { name string - pipeline interface{} + pipeline any arr bson.A hasOutputStage bool err error @@ -246,7 +246,7 @@ func TestMarshalAggregatePipeline(t *testing.T) { }, { "bson.A/success", - bson.A{bson.D{{"$limit", int32(12345)}}, map[string]interface{}{"$count": "foobar"}}, + bson.A{bson.D{{"$limit", int32(12345)}}, map[string]any{"$count": "foobar"}}, bson.A{ bson.D{{"$limit", int(12345)}}, bson.D{{"$count", "foobar"}}, @@ -263,7 +263,7 @@ func TestMarshalAggregatePipeline(t *testing.T) { }, { "bson.A/success", - bson.A{bson.D{{"$limit", int32(12345)}}, map[string]interface{}{"$count": "foobar"}}, + bson.A{bson.D{{"$limit", int32(12345)}}, map[string]any{"$count": "foobar"}}, bson.A{ bson.D{{"$limit", int32(12345)}}, bson.D{{"$count", "foobar"}}, @@ -272,15 +272,15 @@ func TestMarshalAggregatePipeline(t *testing.T) { nil, }, { - "[]interface{}/error", - []interface{}{"5"}, + "[]any/error", + []any{"5"}, nil, false, MarshalError{Value: "", Err: errors.New("WriteString can only write while positioned on a Element or Value but is positioned on a TopLevel")}, }, { - "[]interface{}/success", - []interface{}{bson.D{{"$limit", int32(12345)}}, map[string]interface{}{"$count": "foobar"}}, + "[]any/success", + []any{bson.D{{"$limit", int32(12345)}}, map[string]any{"$count": "foobar"}}, bson.A{ bson.D{{"$limit", int32(12345)}}, bson.D{{"$count", "foobar"}}, @@ -341,14 +341,14 @@ func TestMarshalAggregatePipeline(t *testing.T) { }, { "array/error", - [1]interface{}{int64(42)}, + [1]any{int64(42)}, nil, false, MarshalError{Value: int64(0), Err: errors.New("WriteInt64 can only write while positioned on a Element or Value but is positioned on a TopLevel")}, }, { "array/success", - [1]interface{}{bson.D{{"$limit", int64(12345)}}}, + [1]any{bson.D{{"$limit", int64(12345)}}}, bson.A{ bson.D{{"$limit", int64(12345)}}, }, @@ -357,14 +357,14 @@ func TestMarshalAggregatePipeline(t *testing.T) { }, { "slice/error", - []interface{}{int64(42)}, + []any{int64(42)}, nil, false, MarshalError{Value: int64(0), Err: errors.New("WriteInt64 can only write while positioned on a Element or Value but is positioned on a TopLevel")}, }, { "slice/success", - []interface{}{bson.D{{"$limit", int64(12345)}}}, + []any{bson.D{{"$limit", int64(12345)}}}, bson.A{ bson.D{{"$limit", int64(12345)}}, }, @@ -526,7 +526,7 @@ func TestMarshalValue(t *testing.T) { testCases := []struct { name string - value interface{} + value any bsonOpts *options.BSONOptions registry *bson.Registry want bsoncore.Value @@ -560,7 +560,7 @@ func TestMarshalValue(t *testing.T) { value: struct { Int int64 NilBytes []byte - NilMap map[string]interface{} + NilMap map[string]any NilStrings []string ZeroStruct struct{ X int } `bson:"_,omitempty"` StringerMap map[*bson.RawValue]bool diff --git a/mongo/mongocryptd.go b/mongo/mongocryptd.go index 9e6e9daf11..66aa12b954 100644 --- a/mongo/mongocryptd.go +++ b/mongo/mongocryptd.go @@ -132,7 +132,7 @@ func (mc *mongocryptdClient) spawnProcess() error { } // createSpawnArgs creates arguments to spawn mcryptClient. It returns the path and a slice of arguments. -func createSpawnArgs(opts map[string]interface{}) (string, []string) { +func createSpawnArgs(opts map[string]any) (string, []string) { var spawnArgs []string // get command path diff --git a/mongo/options/aggregateoptions.go b/mongo/options/aggregateoptions.go index 070e126583..58ca97d6c4 100644 --- a/mongo/options/aggregateoptions.go +++ b/mongo/options/aggregateoptions.go @@ -23,9 +23,9 @@ type AggregateOptions struct { BypassDocumentValidation *bool Collation *Collation MaxAwaitTime *time.Duration - Comment interface{} - Hint interface{} - Let interface{} + Comment any + Hint any + Let any Custom bson.M // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any @@ -116,7 +116,7 @@ func (ao *AggregateOptionsBuilder) SetMaxAwaitTime(d time.Duration) *AggregateOp // SetComment sets the value for the Comment field. Specifies a string or document that will be included in // server logs, profiling logs, and currentOp queries to help trace the operation. The default is nil, // which means that no comment will be included in the logs. -func (ao *AggregateOptionsBuilder) SetComment(comment interface{}) *AggregateOptionsBuilder { +func (ao *AggregateOptionsBuilder) SetComment(comment any) *AggregateOptionsBuilder { ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error { opts.Comment = comment @@ -130,7 +130,7 @@ func (ao *AggregateOptionsBuilder) SetComment(comment interface{}) *AggregateOpt // either be the index name as a string or the index specification as a document. The hint does not apply to // $lookup and $graphLookup aggregation stages. 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 (ao *AggregateOptionsBuilder) SetHint(h interface{}) *AggregateOptionsBuilder { +func (ao *AggregateOptionsBuilder) SetHint(h any) *AggregateOptionsBuilder { ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error { opts.Hint = h @@ -145,7 +145,7 @@ func (ao *AggregateOptionsBuilder) SetHint(h interface{}) *AggregateOptionsBuild // option. This must be a document mapping parameter names to values. Values must be constant or closed // expressions that do not reference document fields. Parameters can then be accessed as variables in // an aggregate expression context (e.g. "$$var"). -func (ao *AggregateOptionsBuilder) SetLet(let interface{}) *AggregateOptionsBuilder { +func (ao *AggregateOptionsBuilder) SetLet(let any) *AggregateOptionsBuilder { ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error { opts.Let = let diff --git a/mongo/options/autoencryptionoptions.go b/mongo/options/autoencryptionoptions.go index 64c7c90817..db3508fb4f 100644 --- a/mongo/options/autoencryptionoptions.go +++ b/mongo/options/autoencryptionoptions.go @@ -33,13 +33,13 @@ import ( type AutoEncryptionOptions struct { KeyVaultClientOptions *ClientOptions KeyVaultNamespace string - KmsProviders map[string]map[string]interface{} - SchemaMap map[string]interface{} + KmsProviders map[string]map[string]any + SchemaMap map[string]any BypassAutoEncryption *bool - ExtraOptions map[string]interface{} + ExtraOptions map[string]any TLSConfig map[string]*tls.Config HTTPClient *http.Client - EncryptedFieldsMap map[string]interface{} + EncryptedFieldsMap map[string]any BypassQueryAnalysis *bool KeyExpiration *time.Duration } @@ -74,7 +74,7 @@ func (a *AutoEncryptionOptions) SetKeyVaultNamespace(ns string) *AutoEncryptionO } // SetKmsProviders specifies options for KMS providers. This is required. -func (a *AutoEncryptionOptions) SetKmsProviders(providers map[string]map[string]interface{}) *AutoEncryptionOptions { +func (a *AutoEncryptionOptions) SetKmsProviders(providers map[string]map[string]any) *AutoEncryptionOptions { a.KmsProviders = providers return a @@ -87,7 +87,7 @@ func (a *AutoEncryptionOptions) SetKmsProviders(providers map[string]map[string] // Supplying a schemaMap provides more security than relying on JSON Schemas obtained from the server. It protects // against a malicious server advertising a false JSON Schema, which could trick the client into sending unencrypted // data that should be encrypted. -func (a *AutoEncryptionOptions) SetSchemaMap(schemaMap map[string]interface{}) *AutoEncryptionOptions { +func (a *AutoEncryptionOptions) SetSchemaMap(schemaMap map[string]any) *AutoEncryptionOptions { a.SchemaMap = schemaMap return a @@ -136,7 +136,7 @@ func (a *AutoEncryptionOptions) SetBypassAutoEncryption(bypass bool) *AutoEncryp // absolute path to the directory containing the linked libmongocrypt library. Setting an override // path disables the default system library search path. If an override path is specified but the // crypt_shared library cannot be loaded, Client creation will return an error. Must be a string. -func (a *AutoEncryptionOptions) SetExtraOptions(extraOpts map[string]interface{}) *AutoEncryptionOptions { +func (a *AutoEncryptionOptions) SetExtraOptions(extraOpts map[string]any) *AutoEncryptionOptions { a.ExtraOptions = extraOpts return a @@ -153,7 +153,7 @@ func (a *AutoEncryptionOptions) SetTLSConfig(cfg map[string]*tls.Config) *AutoEn // SetEncryptedFieldsMap specifies a map from namespace to local EncryptedFieldsMap document. // EncryptedFieldsMap is used for Queryable Encryption. -func (a *AutoEncryptionOptions) SetEncryptedFieldsMap(ef map[string]interface{}) *AutoEncryptionOptions { +func (a *AutoEncryptionOptions) SetEncryptedFieldsMap(ef map[string]any) *AutoEncryptionOptions { a.EncryptedFieldsMap = ef return a diff --git a/mongo/options/bulkwriteoptions.go b/mongo/options/bulkwriteoptions.go index 20d0395efe..cbdc7f48f4 100644 --- a/mongo/options/bulkwriteoptions.go +++ b/mongo/options/bulkwriteoptions.go @@ -17,9 +17,9 @@ var DefaultOrdered = true // See corresponding setter methods for documentation. type BulkWriteOptions struct { BypassDocumentValidation *bool - Comment interface{} + Comment any Ordered *bool - Let interface{} + Let any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -49,7 +49,7 @@ func (b *BulkWriteOptionsBuilder) List() []func(*BulkWriteOptions) error { // SetComment sets the value for the Comment field. Specifies a string or document that will be included in // server logs, profiling logs, and currentOp queries to help tracethe operation. The default value is nil, // which means that no comment will be included in the logs. -func (b *BulkWriteOptionsBuilder) SetComment(comment interface{}) *BulkWriteOptionsBuilder { +func (b *BulkWriteOptionsBuilder) SetComment(comment any) *BulkWriteOptionsBuilder { b.Opts = append(b.Opts, func(opts *BulkWriteOptions) error { opts.Comment = comment @@ -89,7 +89,7 @@ func (b *BulkWriteOptionsBuilder) SetBypassDocumentValidation(bypass bool) *Bulk // This option is only valid for MongoDB versions >= 5.0. Older servers will report an error for using this option. // This must be a document mapping parameter names to values. Values must be constant or closed expressions that do not // reference document fields. Parameters can then be accessed as variables in an aggregate expression context (e.g. "$$var"). -func (b *BulkWriteOptionsBuilder) SetLet(let interface{}) *BulkWriteOptionsBuilder { +func (b *BulkWriteOptionsBuilder) SetLet(let any) *BulkWriteOptionsBuilder { b.Opts = append(b.Opts, func(opts *BulkWriteOptions) error { opts.Let = &let diff --git a/mongo/options/changestreamoptions.go b/mongo/options/changestreamoptions.go index 5607e10dd0..9e5bb93b02 100644 --- a/mongo/options/changestreamoptions.go +++ b/mongo/options/changestreamoptions.go @@ -18,14 +18,14 @@ import ( type ChangeStreamOptions struct { BatchSize *int32 Collation *Collation - Comment interface{} + Comment any FullDocument *FullDocument FullDocumentBeforeChange *FullDocument MaxAwaitTime *time.Duration - ResumeAfter interface{} + ResumeAfter any ShowExpandedEvents *bool StartAtOperationTime *bson.Timestamp - StartAfter interface{} + StartAfter any Custom bson.M CustomPipeline bson.M } @@ -71,7 +71,7 @@ func (cso *ChangeStreamOptionsBuilder) SetCollation(c Collation) *ChangeStreamOp // SetComment sets the value for the Comment field. Specifies a string or document that will be included in // server logs, profiling logs, and currentOp queries to help trace the operation. The default is nil, // which means that no comment will be included in the logs. -func (cso *ChangeStreamOptionsBuilder) SetComment(comment interface{}) *ChangeStreamOptionsBuilder { +func (cso *ChangeStreamOptionsBuilder) SetComment(comment any) *ChangeStreamOptionsBuilder { cso.Opts = append(cso.Opts, func(opts *ChangeStreamOptions) error { opts.Comment = comment return nil @@ -114,7 +114,7 @@ func (cso *ChangeStreamOptionsBuilder) SetMaxAwaitTime(d time.Duration) *ChangeS // SetResumeAfter sets the value for the ResumeAfter field. Specifies a document specifying the logical starting // point for the change stream. Only changes corresponding to an oplog entry immediately after the resume token // will be returned. If this is specified, StartAtOperationTime and StartAfter must not be set. -func (cso *ChangeStreamOptionsBuilder) SetResumeAfter(rt interface{}) *ChangeStreamOptionsBuilder { +func (cso *ChangeStreamOptionsBuilder) SetResumeAfter(rt any) *ChangeStreamOptionsBuilder { cso.Opts = append(cso.Opts, func(opts *ChangeStreamOptions) error { opts.ResumeAfter = rt return nil @@ -151,7 +151,7 @@ func (cso *ChangeStreamOptionsBuilder) SetStartAtOperationTime(t *bson.Timestamp // the collection has been dropped and recreated or renamed. Only changes corresponding to an oplog entry // immediately after the specified token will be returned. If this is specified, ResumeAfter and // StartAtOperationTime must not be set. This option is only valid for MongoDB versions >= 4.1.1. -func (cso *ChangeStreamOptionsBuilder) SetStartAfter(sa interface{}) *ChangeStreamOptionsBuilder { +func (cso *ChangeStreamOptionsBuilder) SetStartAfter(sa any) *ChangeStreamOptionsBuilder { cso.Opts = append(cso.Opts, func(opts *ChangeStreamOptions) error { opts.StartAfter = sa return nil diff --git a/mongo/options/clientbulkwriteoptions.go b/mongo/options/clientbulkwriteoptions.go index fd6933822b..90d6c24146 100644 --- a/mongo/options/clientbulkwriteoptions.go +++ b/mongo/options/clientbulkwriteoptions.go @@ -16,9 +16,9 @@ import ( // See corresponding setter methods for documentation. type ClientBulkWriteOptions struct { BypassDocumentValidation *bool - Comment interface{} + Comment any Ordered *bool - Let interface{} + Let any WriteConcern *writeconcern.WriteConcern VerboseResults *bool @@ -51,7 +51,7 @@ func (b *ClientBulkWriteOptionsBuilder) List() []func(*ClientBulkWriteOptions) e // SetComment sets the value for the Comment field. Specifies a string or document that will be included in // server logs, profiling logs, and currentOp queries to help tracethe operation. The default value is nil, // which means that no comment will be included in the logs. -func (b *ClientBulkWriteOptionsBuilder) SetComment(comment interface{}) *ClientBulkWriteOptionsBuilder { +func (b *ClientBulkWriteOptionsBuilder) SetComment(comment any) *ClientBulkWriteOptionsBuilder { b.Opts = append(b.Opts, func(opts *ClientBulkWriteOptions) error { opts.Comment = comment @@ -90,7 +90,7 @@ func (b *ClientBulkWriteOptionsBuilder) SetBypassDocumentValidation(bypass bool) // SetLet sets the value for the Let field. Let specifies parameters for all update and delete commands in the BulkWrite. // This must be a document mapping parameter names to values. Values must be constant or closed expressions that do not // reference document fields. Parameters can then be accessed as variables in an aggregate expression context (e.g. "$$var"). -func (b *ClientBulkWriteOptionsBuilder) SetLet(let interface{}) *ClientBulkWriteOptionsBuilder { +func (b *ClientBulkWriteOptionsBuilder) SetLet(let any) *ClientBulkWriteOptionsBuilder { b.Opts = append(b.Opts, func(opts *ClientBulkWriteOptions) error { opts.Let = &let diff --git a/mongo/options/clientencryptionoptions.go b/mongo/options/clientencryptionoptions.go index cd249d0e76..a6c477a7a9 100644 --- a/mongo/options/clientencryptionoptions.go +++ b/mongo/options/clientencryptionoptions.go @@ -20,7 +20,7 @@ import ( // See corresponding setter methods for documentation. type ClientEncryptionOptions struct { KeyVaultNamespace string - KmsProviders map[string]map[string]interface{} + KmsProviders map[string]map[string]any TLSConfig map[string]*tls.Config HTTPClient *http.Client KeyExpiration *time.Duration @@ -60,7 +60,7 @@ func (c *ClientEncryptionOptionsBuilder) SetKeyVaultNamespace(ns string) *Client } // SetKmsProviders specifies options for KMS providers. This is required. -func (c *ClientEncryptionOptionsBuilder) SetKmsProviders(providers map[string]map[string]interface{}) *ClientEncryptionOptionsBuilder { +func (c *ClientEncryptionOptionsBuilder) SetKmsProviders(providers map[string]map[string]any) *ClientEncryptionOptionsBuilder { c.Opts = append(c.Opts, func(opts *ClientEncryptionOptions) error { opts.KmsProviders = providers return nil @@ -117,7 +117,7 @@ func (c *ClientEncryptionOptionsBuilder) SetKeyExpiration(expiration time.Durati // to be considered trusted when making a TLS connection (e.g. "tlsCaFile=/path/to/caFile"). // // This should only be used to set custom TLS options. By default, the connection will use an empty tls.Config{} with MinVersion set to tls.VersionTLS12. -func BuildTLSConfig(tlsOpts map[string]interface{}) (*tls.Config, error) { +func BuildTLSConfig(tlsOpts map[string]any) (*tls.Config, error) { // use TLS min version 1.2 to enforce more secure hash algorithms and advanced cipher suites cfg := &tls.Config{MinVersion: tls.VersionTLS12} diff --git a/mongo/options/clientoptions.go b/mongo/options/clientoptions.go index a4f17e36ad..adc880a5e9 100644 --- a/mongo/options/clientoptions.go +++ b/mongo/options/clientoptions.go @@ -207,7 +207,7 @@ type BSONOptions struct { // DefaultDocumentM causes the driver to always unmarshal documents into the // bson.M type. This behavior is restricted to data typed as - // "interface{}" or "map[string]interface{}". + // "any" or "map[string]any". DefaultDocumentM bool // ObjectIDAsHexString causes the Decoder to decode object IDs to their hex diff --git a/mongo/options/clientoptions_test.go b/mongo/options/clientoptions_test.go index 3457bc43f1..07e3c12bdc 100644 --- a/mongo/options/clientoptions_test.go +++ b/mongo/options/clientoptions_test.go @@ -52,10 +52,10 @@ func TestClientOptions(t *testing.T) { t.Run("Set", func(t *testing.T) { testCases := []struct { name string - fn interface{} // method to be run - arg interface{} // argument for method - field string // field to be set - dereference bool // Should we compare a pointer or the field + fn any // method to be run + arg any // argument for method + field string // field to be set + dereference bool // Should we compare a pointer or the field }{ {"AppName", (*ClientOptions).SetAppName, "example-application", "AppName", true}, {"Auth", (*ClientOptions).SetAuth, Credential{Username: "foo", Password: "bar"}, "Auth", true}, diff --git a/mongo/options/countoptions.go b/mongo/options/countoptions.go index 3e689d9a54..9cf5924a4a 100644 --- a/mongo/options/countoptions.go +++ b/mongo/options/countoptions.go @@ -14,8 +14,8 @@ import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" // See corresponding setter methods for documentation. type CountOptions struct { Collation *Collation - Comment interface{} - Hint interface{} + Comment any + Hint any Limit *int64 Skip *int64 @@ -57,7 +57,7 @@ func (co *CountOptionsBuilder) SetCollation(c *Collation) *CountOptionsBuilder { // SetComment sets the value for the Comment field. Specifies a string or document that will be included // in server logs, profiling logs, and currentOp queries to help trace the operation. The default is nil, // which means that no comment will be included in the logs. -func (co *CountOptionsBuilder) SetComment(comment interface{}) *CountOptionsBuilder { +func (co *CountOptionsBuilder) SetComment(comment any) *CountOptionsBuilder { co.Opts = append(co.Opts, func(opts *CountOptions) error { opts.Comment = comment @@ -71,7 +71,7 @@ func (co *CountOptionsBuilder) SetComment(comment interface{}) *CountOptionsBuil // either be the index name as a string or the index specification as a document. 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 (co *CountOptionsBuilder) SetHint(h interface{}) *CountOptionsBuilder { +func (co *CountOptionsBuilder) SetHint(h any) *CountOptionsBuilder { co.Opts = append(co.Opts, func(opts *CountOptions) error { opts.Hint = h diff --git a/mongo/options/createcollectionoptions.go b/mongo/options/createcollectionoptions.go index d1231758f3..4bac0d0409 100644 --- a/mongo/options/createcollectionoptions.go +++ b/mongo/options/createcollectionoptions.go @@ -16,7 +16,7 @@ import ( // // See corresponding setter methods for documentation. type DefaultIndexOptions struct { - StorageEngine interface{} + StorageEngine any } // DefaultIndexOptionsBuilder contains options to configure default index @@ -39,7 +39,7 @@ func (d *DefaultIndexOptionsBuilder) List() []func(*DefaultIndexOptions) error { // SetStorageEngine sets the value for the StorageEngine field. Specifies the storage engine to use for // the index. The value must be a document in the form {: }. The default // value is nil, which means that the default storage engine will be used. -func (d *DefaultIndexOptionsBuilder) SetStorageEngine(storageEngine interface{}) *DefaultIndexOptionsBuilder { +func (d *DefaultIndexOptionsBuilder) SetStorageEngine(storageEngine any) *DefaultIndexOptionsBuilder { d.Opts = append(d.Opts, func(opts *DefaultIndexOptions) error { opts.StorageEngine = storageEngine @@ -149,18 +149,18 @@ func (tso *TimeSeriesOptionsBuilder) SetBucketRounding(dur time.Duration) *TimeS type CreateCollectionOptions struct { Capped *bool Collation *Collation - ChangeStreamPreAndPostImages interface{} + ChangeStreamPreAndPostImages any DefaultIndexOptions *DefaultIndexOptionsBuilder MaxDocuments *int64 SizeInBytes *int64 - StorageEngine interface{} + StorageEngine any ValidationAction *string ValidationLevel *string - Validator interface{} + Validator any ExpireAfterSeconds *int64 TimeSeriesOptions *TimeSeriesOptionsBuilder - EncryptedFields interface{} - ClusteredIndex interface{} + EncryptedFields any + ClusteredIndex any } // CreateCollectionOptionsBuilder contains options to configure a new @@ -211,7 +211,7 @@ func (c *CreateCollectionOptionsBuilder) SetCollation(collation *Collation) *Cre // option is only valid for MongoDB versions >= 6.0. The default value is nil, which means that // change streams opened against the collection will not return pre- and post-images of updated // documents in any way. -func (c *CreateCollectionOptionsBuilder) SetChangeStreamPreAndPostImages(csppi interface{}) *CreateCollectionOptionsBuilder { +func (c *CreateCollectionOptionsBuilder) SetChangeStreamPreAndPostImages(csppi any) *CreateCollectionOptionsBuilder { c.Opts = append(c.Opts, func(opts *CreateCollectionOptions) error { opts.ChangeStreamPreAndPostImages = &csppi @@ -264,7 +264,7 @@ func (c *CreateCollectionOptionsBuilder) SetSizeInBytes(size int64) *CreateColle // SetStorageEngine sets the value for the StorageEngine field. Specifies the storage engine to use for // the index. The value must be a document in the form {: }. The default // value is nil, which means that the default storage engine will be used. -func (c *CreateCollectionOptionsBuilder) SetStorageEngine(storageEngine interface{}) *CreateCollectionOptionsBuilder { +func (c *CreateCollectionOptionsBuilder) SetStorageEngine(storageEngine any) *CreateCollectionOptionsBuilder { c.Opts = append(c.Opts, func(opts *CreateCollectionOptions) error { opts.StorageEngine = &storageEngine @@ -305,7 +305,7 @@ func (c *CreateCollectionOptionsBuilder) SetValidationLevel(level string) *Creat // SetValidator sets the value for the Validator field. Sets a document specifying validation rules for the // collection. See https://www.mongodb.com/docs/manual/core/schema-validation/ for more information about // schema validation. The default value is nil, meaning no validator will be used for the collection. -func (c *CreateCollectionOptionsBuilder) SetValidator(validator interface{}) *CreateCollectionOptionsBuilder { +func (c *CreateCollectionOptionsBuilder) SetValidator(validator any) *CreateCollectionOptionsBuilder { c.Opts = append(c.Opts, func(opts *CreateCollectionOptions) error { opts.Validator = validator @@ -351,7 +351,7 @@ func (c *CreateCollectionOptionsBuilder) SetTimeSeriesOptions(timeSeriesOpts *Ti // SetEncryptedFields sets the encrypted fields for encrypted collections. // // This option is only valid for MongoDB versions >= 6.0 -func (c *CreateCollectionOptionsBuilder) SetEncryptedFields(encryptedFields interface{}) *CreateCollectionOptionsBuilder { +func (c *CreateCollectionOptionsBuilder) SetEncryptedFields(encryptedFields any) *CreateCollectionOptionsBuilder { c.Opts = append(c.Opts, func(opts *CreateCollectionOptions) error { opts.EncryptedFields = encryptedFields @@ -365,7 +365,7 @@ func (c *CreateCollectionOptionsBuilder) SetEncryptedFields(encryptedFields inte // to create a collection with a clustered index. // // This option is only valid for MongoDB versions >= 5.3 -func (c *CreateCollectionOptionsBuilder) SetClusteredIndex(clusteredIndex interface{}) *CreateCollectionOptionsBuilder { +func (c *CreateCollectionOptionsBuilder) SetClusteredIndex(clusteredIndex any) *CreateCollectionOptionsBuilder { c.Opts = append(c.Opts, func(opts *CreateCollectionOptions) error { opts.ClusteredIndex = clusteredIndex diff --git a/mongo/options/datakeyoptions.go b/mongo/options/datakeyoptions.go index b7b2a19284..8d24f9d150 100644 --- a/mongo/options/datakeyoptions.go +++ b/mongo/options/datakeyoptions.go @@ -10,7 +10,7 @@ package options // // See corresponding setter methods for documentation. type DataKeyOptions struct { - MasterKey interface{} + MasterKey any KeyAltNames []string KeyMaterial []byte } @@ -71,7 +71,7 @@ func (dk *DataKeyOptionsBuilder) List() []func(*DataKeyOptions) error { // } // // If unset, "keyVersion" defaults to the key's primary version and "endpoint" defaults to "cloudkms.googleapis.com". -func (dk *DataKeyOptionsBuilder) SetMasterKey(masterKey interface{}) *DataKeyOptionsBuilder { +func (dk *DataKeyOptionsBuilder) SetMasterKey(masterKey any) *DataKeyOptionsBuilder { dk.Opts = append(dk.Opts, func(opts *DataKeyOptions) error { opts.MasterKey = masterKey diff --git a/mongo/options/deleteoptions.go b/mongo/options/deleteoptions.go index 27a77b4581..2206abb24e 100644 --- a/mongo/options/deleteoptions.go +++ b/mongo/options/deleteoptions.go @@ -14,9 +14,9 @@ import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" // See corresponding setter methods for documentation. type DeleteOneOptions struct { Collation *Collation - Comment interface{} - Hint interface{} - Let interface{} + Comment any + Hint any + Let any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -56,7 +56,7 @@ func (do *DeleteOneOptionsBuilder) SetCollation(c *Collation) *DeleteOneOptionsB // SetComment sets the value for the Comment field. Specifies a string or document that will // be included in server logs, profiling logs, and currentOp queries to help trace the operation. // The default value is nil, which means that no comment will be included in the logs. -func (do *DeleteOneOptionsBuilder) SetComment(comment interface{}) *DeleteOneOptionsBuilder { +func (do *DeleteOneOptionsBuilder) SetComment(comment any) *DeleteOneOptionsBuilder { do.Opts = append(do.Opts, func(opts *DeleteOneOptions) error { opts.Comment = comment @@ -74,7 +74,7 @@ func (do *DeleteOneOptionsBuilder) SetComment(comment interface{}) *DeleteOneOpt // 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 (do *DeleteOneOptionsBuilder) SetHint(hint interface{}) *DeleteOneOptionsBuilder { +func (do *DeleteOneOptionsBuilder) SetHint(hint any) *DeleteOneOptionsBuilder { do.Opts = append(do.Opts, func(opts *DeleteOneOptions) error { opts.Hint = hint @@ -89,7 +89,7 @@ func (do *DeleteOneOptionsBuilder) SetHint(hint interface{}) *DeleteOneOptionsBu // this option. This must be a document mapping parameter names to values. Values must be constant // or closed expressions that do not reference document fields. Parameters can then be accessed as // variables in an aggregate expression context (e.g. "$$var"). -func (do *DeleteOneOptionsBuilder) SetLet(let interface{}) *DeleteOneOptionsBuilder { +func (do *DeleteOneOptionsBuilder) SetLet(let any) *DeleteOneOptionsBuilder { do.Opts = append(do.Opts, func(opts *DeleteOneOptions) error { opts.Let = let @@ -105,9 +105,9 @@ func (do *DeleteOneOptionsBuilder) SetLet(let interface{}) *DeleteOneOptionsBuil // See corresponding setter methods for documentation. type DeleteManyOptions struct { Collation *Collation - Comment interface{} - Hint interface{} - Let interface{} + Comment any + Hint any + Let any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -147,7 +147,7 @@ func (do *DeleteManyOptionsBuilder) SetCollation(c *Collation) *DeleteManyOption // SetComment sets the value for the Comment field. Specifies a string or document that will be // included in server logs, profiling logs, and currentOp queries to help trace the operation. // The default value is nil, which means that no comment will be included in the logs. -func (do *DeleteManyOptionsBuilder) SetComment(comment interface{}) *DeleteManyOptionsBuilder { +func (do *DeleteManyOptionsBuilder) SetComment(comment any) *DeleteManyOptionsBuilder { do.Opts = append(do.Opts, func(opts *DeleteManyOptions) error { opts.Comment = comment @@ -165,7 +165,7 @@ func (do *DeleteManyOptionsBuilder) SetComment(comment interface{}) *DeleteManyO // 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 (do *DeleteManyOptionsBuilder) SetHint(hint interface{}) *DeleteManyOptionsBuilder { +func (do *DeleteManyOptionsBuilder) SetHint(hint any) *DeleteManyOptionsBuilder { do.Opts = append(do.Opts, func(opts *DeleteManyOptions) error { opts.Hint = hint @@ -180,7 +180,7 @@ func (do *DeleteManyOptionsBuilder) SetHint(hint interface{}) *DeleteManyOptions // for using this option. This must be a document mapping parameter names to values. Values // must be constant or closed expressions that do not reference document fields. Parameters // can then be accessed as variables in an aggregate expression context (e.g. "$$var"). -func (do *DeleteManyOptionsBuilder) SetLet(let interface{}) *DeleteManyOptionsBuilder { +func (do *DeleteManyOptionsBuilder) SetLet(let any) *DeleteManyOptionsBuilder { do.Opts = append(do.Opts, func(opts *DeleteManyOptions) error { opts.Let = let diff --git a/mongo/options/distinctoptions.go b/mongo/options/distinctoptions.go index 346432c07a..476c10480e 100644 --- a/mongo/options/distinctoptions.go +++ b/mongo/options/distinctoptions.go @@ -14,8 +14,8 @@ import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" // See corresponding setter methods for documentation. type DistinctOptions struct { Collation *Collation - Comment interface{} - Hint interface{} + Comment any + Hint any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -56,7 +56,7 @@ func (do *DistinctOptionsBuilder) SetCollation(c *Collation) *DistinctOptionsBui // will be included in server logs, profiling logs, and currentOp queries to help trace // the operation. The default value is nil, which means that no comment will be included // in the logs. -func (do *DistinctOptionsBuilder) SetComment(comment interface{}) *DistinctOptionsBuilder { +func (do *DistinctOptionsBuilder) SetComment(comment any) *DistinctOptionsBuilder { do.Opts = append(do.Opts, func(opts *DistinctOptions) error { opts.Comment = comment @@ -74,7 +74,7 @@ func (do *DistinctOptionsBuilder) SetComment(comment interface{}) *DistinctOptio // means that no index hint will be sent. // // SetHint sets the Hint field. -func (do *DistinctOptionsBuilder) SetHint(hint interface{}) *DistinctOptionsBuilder { +func (do *DistinctOptionsBuilder) SetHint(hint any) *DistinctOptionsBuilder { do.Opts = append(do.Opts, func(opts *DistinctOptions) error { opts.Hint = hint diff --git a/mongo/options/dropcollectionoptions.go b/mongo/options/dropcollectionoptions.go index 4619b6b680..013b4bbb77 100644 --- a/mongo/options/dropcollectionoptions.go +++ b/mongo/options/dropcollectionoptions.go @@ -11,7 +11,7 @@ package options // // See corresponding setter methods for documentation. type DropCollectionOptions struct { - EncryptedFields interface{} + EncryptedFields any } // DropCollectionOptionsBuilder contains options to configure collection drop @@ -34,7 +34,7 @@ func (d *DropCollectionOptionsBuilder) List() []func(*DropCollectionOptions) err // SetEncryptedFields sets the encrypted fields for encrypted collections. // // This option is only valid for MongoDB versions >= 6.0 -func (d *DropCollectionOptionsBuilder) SetEncryptedFields(encryptedFields interface{}) *DropCollectionOptionsBuilder { +func (d *DropCollectionOptionsBuilder) SetEncryptedFields(encryptedFields any) *DropCollectionOptionsBuilder { d.Opts = append(d.Opts, func(opts *DropCollectionOptions) error { opts.EncryptedFields = encryptedFields diff --git a/mongo/options/estimatedcountoptions.go b/mongo/options/estimatedcountoptions.go index ccddd98c59..2fd8f87dfd 100644 --- a/mongo/options/estimatedcountoptions.go +++ b/mongo/options/estimatedcountoptions.go @@ -13,7 +13,7 @@ import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" // // See corresponding setter methods for documentation. type EstimatedDocumentCountOptions struct { - Comment interface{} + Comment any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -41,7 +41,7 @@ func (eco *EstimatedDocumentCountOptionsBuilder) List() []func(*EstimatedDocumen // that will be included in server logs, profiling logs, and currentOp queries to help // trace the operation. The default is nil, which means that no comment will be // included in the logs. -func (eco *EstimatedDocumentCountOptionsBuilder) SetComment(comment interface{}) *EstimatedDocumentCountOptionsBuilder { +func (eco *EstimatedDocumentCountOptionsBuilder) SetComment(comment any) *EstimatedDocumentCountOptionsBuilder { eco.Opts = append(eco.Opts, func(opts *EstimatedDocumentCountOptions) error { opts.Comment = comment diff --git a/mongo/options/example_test.go b/mongo/options/example_test.go index a4cb92ee11..1abca94b2e 100644 --- a/mongo/options/example_test.go +++ b/mongo/options/example_test.go @@ -23,14 +23,14 @@ type CustomLogger struct { mu sync.Mutex } -func (logger *CustomLogger) Info(level int, msg string, _ ...interface{}) { +func (logger *CustomLogger) Info(level int, msg string, _ ...any) { logger.mu.Lock() defer logger.mu.Unlock() fmt.Fprintf(logger, "level=%d msg=%s\n", level, msg) } -func (logger *CustomLogger) Error(err error, msg string, _ ...interface{}) { +func (logger *CustomLogger) Error(err error, msg string, _ ...any) { logger.mu.Lock() defer logger.mu.Unlock() diff --git a/mongo/options/findoptions.go b/mongo/options/findoptions.go index dd66eabc7a..b295bd514f 100644 --- a/mongo/options/findoptions.go +++ b/mongo/options/findoptions.go @@ -19,22 +19,22 @@ import ( type FindOptions struct { AllowPartialResults *bool Collation *Collation - Comment interface{} - Hint interface{} - Max interface{} + Comment any + Hint any + Max any MaxAwaitTime *time.Duration - Min interface{} + Min any OplogReplay *bool - Projection interface{} + Projection any ReturnKey *bool ShowRecordID *bool Skip *int64 - Sort interface{} + Sort any // The above are in common with FindOneopts. AllowDiskUse *bool BatchSize *int32 CursorType *CursorType - Let interface{} + Let any Limit *int64 NoCursorTimeout *bool @@ -107,7 +107,7 @@ func (f *FindOptionsBuilder) SetCollation(collation *Collation) *FindOptionsBuil // SetComment sets the value for the Comment field. Specifies a string or document that will be // included in server logs, profiling logs, and currentOp queries to help trace the operation. // The default is nil, which means that no comment will be included in the logs. -func (f *FindOptionsBuilder) SetComment(comment interface{}) *FindOptionsBuilder { +func (f *FindOptionsBuilder) SetComment(comment any) *FindOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOptions) error { opts.Comment = &comment return nil @@ -130,7 +130,7 @@ func (f *FindOptionsBuilder) SetCursorType(ct CursorType) *FindOptionsBuilder { // This should either be the index name as a string or the index specification as a document. // 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 (f *FindOptionsBuilder) SetHint(hint interface{}) *FindOptionsBuilder { +func (f *FindOptionsBuilder) SetHint(hint any) *FindOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOptions) error { opts.Hint = hint return nil @@ -143,7 +143,7 @@ func (f *FindOptionsBuilder) SetHint(hint interface{}) *FindOptionsBuilder { // for using this option. This must be a document mapping parameter names to values. Values // must be constant or closed expressions that do not reference document fields. Parameters // can then be accessed as variables in an aggregate expression context (e.g. "$$var"). -func (f *FindOptionsBuilder) SetLet(let interface{}) *FindOptionsBuilder { +func (f *FindOptionsBuilder) SetLet(let any) *FindOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOptions) error { opts.Let = let return nil @@ -165,7 +165,7 @@ func (f *FindOptionsBuilder) SetLimit(i int64) *FindOptionsBuilder { // SetMax sets the value for the Max field. Max is a document specifying the exclusive upper bound // for a specific index. The default value is nil, which means that there is no maximum value. -func (f *FindOptionsBuilder) SetMax(max interface{}) *FindOptionsBuilder { +func (f *FindOptionsBuilder) SetMax(max any) *FindOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOptions) error { opts.Max = max return nil @@ -188,7 +188,7 @@ func (f *FindOptionsBuilder) SetMaxAwaitTime(d time.Duration) *FindOptionsBuilde // SetMin sets the value for the Min field. Min is a document specifying the inclusive lower bound // for a specific index. The default value is 0, which means that there is no minimum value. -func (f *FindOptionsBuilder) SetMin(min interface{}) *FindOptionsBuilder { +func (f *FindOptionsBuilder) SetMin(min any) *FindOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOptions) error { opts.Min = min return nil @@ -223,7 +223,7 @@ func (f *FindOptionsBuilder) SetOplogReplay(b bool) *FindOptionsBuilder { // SetProjection sets the value for the Projection field. Projection is a document describing // which fields will be included in the documents returned by the Find operation. The // default value is nil, which means all fields will be included. -func (f *FindOptionsBuilder) SetProjection(projection interface{}) *FindOptionsBuilder { +func (f *FindOptionsBuilder) SetProjection(projection any) *FindOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOptions) error { opts.Projection = projection return nil @@ -266,7 +266,7 @@ func (f *FindOptionsBuilder) SetSkip(i int64) *FindOptionsBuilder { // SetSort sets the value for the Sort field. Sort is a document specifying the order in which // documents should be returned. 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 (f *FindOptionsBuilder) SetSort(sort interface{}) *FindOptionsBuilder { +func (f *FindOptionsBuilder) SetSort(sort any) *FindOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOptions) error { opts.Sort = sort return nil @@ -281,16 +281,16 @@ func (f *FindOptionsBuilder) SetSort(sort interface{}) *FindOptionsBuilder { type FindOneOptions struct { AllowPartialResults *bool Collation *Collation - Comment interface{} - Hint interface{} - Max interface{} - Min interface{} + Comment any + Hint any + Max any + Min any OplogReplay *bool - Projection interface{} + Projection any ReturnKey *bool ShowRecordID *bool Skip *int64 - Sort interface{} + Sort any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -338,7 +338,7 @@ func (f *FindOneOptionsBuilder) SetCollation(collation *Collation) *FindOneOptio // SetComment sets the value for the Comment field. Specifies a string or document that will be // included in server logs, profiling logs, and currentOp queries to help trace the operation. // The default is nil, which means that no comment will be included in the logs. -func (f *FindOneOptionsBuilder) SetComment(comment interface{}) *FindOneOptionsBuilder { +func (f *FindOneOptionsBuilder) SetComment(comment any) *FindOneOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneOptions) error { opts.Comment = &comment return nil @@ -350,7 +350,7 @@ func (f *FindOneOptionsBuilder) SetComment(comment interface{}) *FindOneOptionsB // This should either be the index name as a string or the index specification as a document. // 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 (f *FindOneOptionsBuilder) SetHint(hint interface{}) *FindOneOptionsBuilder { +func (f *FindOneOptionsBuilder) SetHint(hint any) *FindOneOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneOptions) error { opts.Hint = hint return nil @@ -360,7 +360,7 @@ func (f *FindOneOptionsBuilder) SetHint(hint interface{}) *FindOneOptionsBuilder // SetMax sets the value for the Max field. Sets a document specifying the exclusive upper bound // for a specific index. The default value is nil, which means that there is no maximum value. -func (f *FindOneOptionsBuilder) SetMax(max interface{}) *FindOneOptionsBuilder { +func (f *FindOneOptionsBuilder) SetMax(max any) *FindOneOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneOptions) error { opts.Max = max return nil @@ -370,7 +370,7 @@ func (f *FindOneOptionsBuilder) SetMax(max interface{}) *FindOneOptionsBuilder { // SetMin sets the value for the Min field. Sets a document specifying the inclusive lower bound // for a specific index. The default value is 0, which means that there is no minimum value. -func (f *FindOneOptionsBuilder) SetMin(min interface{}) *FindOneOptionsBuilder { +func (f *FindOneOptionsBuilder) SetMin(min any) *FindOneOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneOptions) error { opts.Min = min return nil @@ -394,7 +394,7 @@ func (f *FindOneOptionsBuilder) SetOplogReplay(b bool) *FindOneOptionsBuilder { // SetProjection sets the value for the Projection field. Sets a document describing which fields // will be included in the document returned by the operation. The default value is nil, which // means all fields will be included. -func (f *FindOneOptionsBuilder) SetProjection(projection interface{}) *FindOneOptionsBuilder { +func (f *FindOneOptionsBuilder) SetProjection(projection any) *FindOneOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneOptions) error { opts.Projection = projection return nil @@ -438,7 +438,7 @@ func (f *FindOneOptionsBuilder) SetSkip(i int64) *FindOneOptionsBuilder { // apply to the query. The first document in the sorted order will be returned. 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 (f *FindOneOptionsBuilder) SetSort(sort interface{}) *FindOneOptionsBuilder { +func (f *FindOneOptionsBuilder) SetSort(sort any) *FindOneOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneOptions) error { opts.Sort = sort return nil @@ -453,13 +453,13 @@ func (f *FindOneOptionsBuilder) SetSort(sort interface{}) *FindOneOptionsBuilder type FindOneAndReplaceOptions struct { BypassDocumentValidation *bool Collation *Collation - Comment interface{} - Projection interface{} + Comment any + Projection any ReturnDocument *ReturnDocument - Sort interface{} + Sort any Upsert *bool - Hint interface{} - Let interface{} + Hint any + Let any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -513,7 +513,7 @@ func (f *FindOneAndReplaceOptionsBuilder) SetCollation(collation *Collation) *Fi // SetComment sets the value for the Comment field. Specifies a string or document that will be // included in server logs, profiling logs, and currentOp queries to help trace the operation. // The default value is nil, which means that no comment will be included in the logs. -func (f *FindOneAndReplaceOptionsBuilder) SetComment(comment interface{}) *FindOneAndReplaceOptionsBuilder { +func (f *FindOneAndReplaceOptionsBuilder) SetComment(comment any) *FindOneAndReplaceOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndReplaceOptions) error { opts.Comment = comment @@ -526,7 +526,7 @@ func (f *FindOneAndReplaceOptionsBuilder) SetComment(comment interface{}) *FindO // SetProjection sets the value for the Projection field. Sets a document describing which fields // will be included in the document returned by the operation. The default value is nil, which // means all fields will be included. -func (f *FindOneAndReplaceOptionsBuilder) SetProjection(projection interface{}) *FindOneAndReplaceOptionsBuilder { +func (f *FindOneAndReplaceOptionsBuilder) SetProjection(projection any) *FindOneAndReplaceOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndReplaceOptions) error { opts.Projection = projection @@ -554,7 +554,7 @@ func (f *FindOneAndReplaceOptionsBuilder) SetReturnDocument(rd ReturnDocument) * // If set, the first document in the sorted order will be replaced. 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 (f *FindOneAndReplaceOptionsBuilder) SetSort(sort interface{}) *FindOneAndReplaceOptionsBuilder { +func (f *FindOneAndReplaceOptionsBuilder) SetSort(sort any) *FindOneAndReplaceOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndReplaceOptions) error { opts.Sort = sort @@ -584,7 +584,7 @@ func (f *FindOneAndReplaceOptionsBuilder) SetUpsert(b bool) *FindOneAndReplaceOp // with 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 (f *FindOneAndReplaceOptionsBuilder) SetHint(hint interface{}) *FindOneAndReplaceOptionsBuilder { +func (f *FindOneAndReplaceOptionsBuilder) SetHint(hint any) *FindOneAndReplaceOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndReplaceOptions) error { opts.Hint = hint @@ -600,7 +600,7 @@ func (f *FindOneAndReplaceOptionsBuilder) SetHint(hint interface{}) *FindOneAndR // parameter names to values. Values must be constant or closed expressions that do not // reference document fields. Parameters can then be accessed as variables in an // aggregate expression context (e.g. "$$var"). -func (f *FindOneAndReplaceOptionsBuilder) SetLet(let interface{}) *FindOneAndReplaceOptionsBuilder { +func (f *FindOneAndReplaceOptionsBuilder) SetLet(let any) *FindOneAndReplaceOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndReplaceOptions) error { opts.Let = let @@ -615,16 +615,16 @@ func (f *FindOneAndReplaceOptionsBuilder) SetLet(let interface{}) *FindOneAndRep // // See corresponding setter methods for documentation. type FindOneAndUpdateOptions struct { - ArrayFilters []interface{} + ArrayFilters []any BypassDocumentValidation *bool Collation *Collation - Comment interface{} - Projection interface{} + Comment any + Projection any ReturnDocument *ReturnDocument - Sort interface{} + Sort any Upsert *bool - Hint interface{} - Let interface{} + Hint any + Let any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -652,7 +652,7 @@ func (f *FindOneAndUpdateOptionsBuilder) List() []func(*FindOneAndUpdateOptions) // set of filters specifying to which array elements an update should apply. The // default value is nil, which means the update will apply to all array // elements. -func (f *FindOneAndUpdateOptionsBuilder) SetArrayFilters(filters []interface{}) *FindOneAndUpdateOptionsBuilder { +func (f *FindOneAndUpdateOptionsBuilder) SetArrayFilters(filters []any) *FindOneAndUpdateOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndUpdateOptions) error { opts.ArrayFilters = filters @@ -692,7 +692,7 @@ func (f *FindOneAndUpdateOptionsBuilder) SetCollation(collation *Collation) *Fin // SetComment sets the value for the Comment field. Specifies a string or document that will be // included in server logs, profiling logs, and currentOp queries to help trace the operation. // The default value is nil, which means that no comment will be included in the logs. -func (f *FindOneAndUpdateOptionsBuilder) SetComment(comment interface{}) *FindOneAndUpdateOptionsBuilder { +func (f *FindOneAndUpdateOptionsBuilder) SetComment(comment any) *FindOneAndUpdateOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndUpdateOptions) error { opts.Comment = comment @@ -705,7 +705,7 @@ func (f *FindOneAndUpdateOptionsBuilder) SetComment(comment interface{}) *FindOn // SetProjection sets the value for the Projection field. Sets a document describing which fields // will be included in the document returned by the operation. The default value is nil, which // means all fields will be included. -func (f *FindOneAndUpdateOptionsBuilder) SetProjection(projection interface{}) *FindOneAndUpdateOptionsBuilder { +func (f *FindOneAndUpdateOptionsBuilder) SetProjection(projection any) *FindOneAndUpdateOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndUpdateOptions) error { opts.Projection = projection @@ -733,7 +733,7 @@ func (f *FindOneAndUpdateOptionsBuilder) SetReturnDocument(rd ReturnDocument) *F // If set, the first document in the sorted order will be updated. 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 (f *FindOneAndUpdateOptionsBuilder) SetSort(sort interface{}) *FindOneAndUpdateOptionsBuilder { +func (f *FindOneAndUpdateOptionsBuilder) SetSort(sort any) *FindOneAndUpdateOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndUpdateOptions) error { opts.Sort = sort @@ -763,7 +763,7 @@ func (f *FindOneAndUpdateOptionsBuilder) SetUpsert(b bool) *FindOneAndUpdateOpti // with 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 (f *FindOneAndUpdateOptionsBuilder) SetHint(hint interface{}) *FindOneAndUpdateOptionsBuilder { +func (f *FindOneAndUpdateOptionsBuilder) SetHint(hint any) *FindOneAndUpdateOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndUpdateOptions) error { opts.Hint = hint @@ -779,7 +779,7 @@ func (f *FindOneAndUpdateOptionsBuilder) SetHint(hint interface{}) *FindOneAndUp // to values. Values must be constant or closed expressions that do not reference document // fields. Parameters can then be accessed as variables in an aggregate expression context // (e.g. "$$var"). -func (f *FindOneAndUpdateOptionsBuilder) SetLet(let interface{}) *FindOneAndUpdateOptionsBuilder { +func (f *FindOneAndUpdateOptionsBuilder) SetLet(let any) *FindOneAndUpdateOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndUpdateOptions) error { opts.Let = let @@ -795,11 +795,11 @@ func (f *FindOneAndUpdateOptionsBuilder) SetLet(let interface{}) *FindOneAndUpda // See corresponding setter methods for documentation. type FindOneAndDeleteOptions struct { Collation *Collation - Comment interface{} - Projection interface{} - Sort interface{} - Hint interface{} - Let interface{} + Comment any + Projection any + Sort any + Hint any + Let any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -839,7 +839,7 @@ func (f *FindOneAndDeleteOptionsBuilder) SetCollation(collation *Collation) *Fin // SetComment sets the value for the Comment field. Specifies a string or document that will be // included in server logs, profiling logs, and currentOp queries to help trace the operation. // The default value is nil, which means that no comment will be included in the logs. -func (f *FindOneAndDeleteOptionsBuilder) SetComment(comment interface{}) *FindOneAndDeleteOptionsBuilder { +func (f *FindOneAndDeleteOptionsBuilder) SetComment(comment any) *FindOneAndDeleteOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndDeleteOptions) error { opts.Comment = comment @@ -852,7 +852,7 @@ func (f *FindOneAndDeleteOptionsBuilder) SetComment(comment interface{}) *FindOn // SetProjection sets the value for the Projection field. Sets a document describing which fields // will be included in the document returned by the operation. The default value is nil, which // means all fields will be included. -func (f *FindOneAndDeleteOptionsBuilder) SetProjection(projection interface{}) *FindOneAndDeleteOptionsBuilder { +func (f *FindOneAndDeleteOptionsBuilder) SetProjection(projection any) *FindOneAndDeleteOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndDeleteOptions) error { opts.Projection = projection @@ -867,7 +867,7 @@ func (f *FindOneAndDeleteOptionsBuilder) SetProjection(projection interface{}) * // If set, the first document in the sorted order will be deleted. 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 (f *FindOneAndDeleteOptionsBuilder) SetSort(sort interface{}) *FindOneAndDeleteOptionsBuilder { +func (f *FindOneAndDeleteOptionsBuilder) SetSort(sort any) *FindOneAndDeleteOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndDeleteOptions) error { opts.Sort = sort @@ -884,7 +884,7 @@ func (f *FindOneAndDeleteOptionsBuilder) SetSort(sort interface{}) *FindOneAndDe // error if this option is specified. The driver will return an error if this option is used // with 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 (f *FindOneAndDeleteOptionsBuilder) SetHint(hint interface{}) *FindOneAndDeleteOptionsBuilder { +func (f *FindOneAndDeleteOptionsBuilder) SetHint(hint any) *FindOneAndDeleteOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndDeleteOptions) error { opts.Hint = hint @@ -899,7 +899,7 @@ func (f *FindOneAndDeleteOptionsBuilder) SetHint(hint interface{}) *FindOneAndDe // report an error for using this option. This must be a document mapping parameter names to // values. Values must be constant or closed expressions that do not reference document fields. // Parameters can then be accessed as variables in an aggregate expression context (e.g. "$$var"). -func (f *FindOneAndDeleteOptionsBuilder) SetLet(let interface{}) *FindOneAndDeleteOptionsBuilder { +func (f *FindOneAndDeleteOptionsBuilder) SetLet(let any) *FindOneAndDeleteOptionsBuilder { f.Opts = append(f.Opts, func(opts *FindOneAndDeleteOptions) error { opts.Let = let diff --git a/mongo/options/gridfsoptions.go b/mongo/options/gridfsoptions.go index 43af42b456..676596cb56 100644 --- a/mongo/options/gridfsoptions.go +++ b/mongo/options/gridfsoptions.go @@ -123,7 +123,7 @@ func (b *BucketOptionsBuilder) SetReadPreference(rp *readpref.ReadPref) *BucketO // See corresponding setter methods for documentation. type GridFSUploadOptions struct { ChunkSizeBytes *int32 - Metadata interface{} + Metadata any Registry *bson.Registry } @@ -163,7 +163,7 @@ func (u *GridFSUploadOptionsBuilder) SetChunkSizeBytes(i int32) *GridFSUploadOpt // that will be stored in the "metadata" field of the document in the files collection. // The default value is nil, which means that the document in the files collection will // not contain a "metadata" field. -func (u *GridFSUploadOptionsBuilder) SetMetadata(doc interface{}) *GridFSUploadOptionsBuilder { +func (u *GridFSUploadOptionsBuilder) SetMetadata(doc any) *GridFSUploadOptionsBuilder { u.Opts = append(u.Opts, func(opts *GridFSUploadOptions) error { opts.Metadata = doc @@ -242,7 +242,7 @@ type GridFSFindOptions struct { Limit *int32 NoCursorTimeout *bool Skip *int32 - Sort interface{} + Sort any } // GridFSFindOptionsBuilder contains options to configure find operations. Each @@ -331,7 +331,7 @@ func (f *GridFSFindOptionsBuilder) SetSkip(i int32) *GridFSFindOptionsBuilder { // in which documents should be returned. 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 (f *GridFSFindOptionsBuilder) SetSort(sort interface{}) *GridFSFindOptionsBuilder { +func (f *GridFSFindOptionsBuilder) SetSort(sort any) *GridFSFindOptionsBuilder { f.Opts = append(f.Opts, func(opts *GridFSFindOptions) error { opts.Sort = sort diff --git a/mongo/options/indexoptions.go b/mongo/options/indexoptions.go index 792bd827a7..309a77ba99 100644 --- a/mongo/options/indexoptions.go +++ b/mongo/options/indexoptions.go @@ -13,7 +13,7 @@ import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" // // See corresponding setter methods for documentation. type CreateIndexesOptions struct { - CommitQuorum interface{} + CommitQuorum any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -199,21 +199,21 @@ type IndexOptions struct { ExpireAfterSeconds *int32 Name *string Sparse *bool - StorageEngine interface{} + StorageEngine any Unique *bool Version *int32 DefaultLanguage *string LanguageOverride *string TextVersion *int32 - Weights interface{} + Weights any SphereVersion *int32 Bits *int32 Max *float64 Min *float64 BucketSize *int32 - PartialFilterExpression interface{} + PartialFilterExpression any Collation *Collation - WildcardProjection interface{} + WildcardProjection any Hidden *bool } @@ -277,7 +277,7 @@ func (i *IndexOptionsBuilder) SetSparse(sparse bool) *IndexOptionsBuilder { // storage engine to use for the index. The value must be a document in the form // {: }. The default value is nil, which means that // the default storage engine will be used. -func (i *IndexOptionsBuilder) SetStorageEngine(engine interface{}) *IndexOptionsBuilder { +func (i *IndexOptionsBuilder) SetStorageEngine(engine any) *IndexOptionsBuilder { i.Opts = append(i.Opts, func(opts *IndexOptions) error { opts.StorageEngine = engine @@ -359,7 +359,7 @@ func (i *IndexOptionsBuilder) SetTextVersion(version int32) *IndexOptionsBuilder // terms of the score. This option is only applicable for text indexes and is ignored // for other index types. The default value is nil, which means that every field will // have a weight of 1. -func (i *IndexOptionsBuilder) SetWeights(weights interface{}) *IndexOptionsBuilder { +func (i *IndexOptionsBuilder) SetWeights(weights any) *IndexOptionsBuilder { i.Opts = append(i.Opts, func(opts *IndexOptions) error { opts.Weights = weights @@ -438,7 +438,7 @@ func (i *IndexOptionsBuilder) SetBucketSize(bucketSize int32) *IndexOptionsBuild // SetPartialFilterExpression sets the value for the PartialFilterExpression field. Sets // a document that defines which collection documents the index should reference. -func (i *IndexOptionsBuilder) SetPartialFilterExpression(expression interface{}) *IndexOptionsBuilder { +func (i *IndexOptionsBuilder) SetPartialFilterExpression(expression any) *IndexOptionsBuilder { i.Opts = append(i.Opts, func(opts *IndexOptions) error { opts.PartialFilterExpression = expression @@ -462,7 +462,7 @@ func (i *IndexOptionsBuilder) SetCollation(collation *Collation) *IndexOptionsBu // SetWildcardProjection sets the value for the WildcardProjection field. Sets a document // that defines the wildcard projection for the index. -func (i *IndexOptionsBuilder) SetWildcardProjection(wildcardProjection interface{}) *IndexOptionsBuilder { +func (i *IndexOptionsBuilder) SetWildcardProjection(wildcardProjection any) *IndexOptionsBuilder { i.Opts = append(i.Opts, func(opts *IndexOptions) error { opts.WildcardProjection = wildcardProjection diff --git a/mongo/options/insertoptions.go b/mongo/options/insertoptions.go index 36f18a987d..532f285063 100644 --- a/mongo/options/insertoptions.go +++ b/mongo/options/insertoptions.go @@ -14,7 +14,7 @@ import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" // See corresponding setter methods for documentation. type InsertOneOptions struct { BypassDocumentValidation *bool - Comment interface{} + Comment any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -51,7 +51,7 @@ func (ioo *InsertOneOptionsBuilder) SetBypassDocumentValidation(b bool) *InsertO // SetComment sets the value for the Comment field. Specifies a string or document that will be included in server logs, profiling logs, and currentOp queries to help trace // the operation. The default value is nil, which means that no comment will be included in the logs. -func (ioo *InsertOneOptionsBuilder) SetComment(comment interface{}) *InsertOneOptionsBuilder { +func (ioo *InsertOneOptionsBuilder) SetComment(comment any) *InsertOneOptionsBuilder { ioo.Opts = append(ioo.Opts, func(opts *InsertOneOptions) error { opts.Comment = &comment return nil @@ -65,7 +65,7 @@ func (ioo *InsertOneOptionsBuilder) SetComment(comment interface{}) *InsertOneOp // See corresponding setter methods for documentation. type InsertManyOptions struct { BypassDocumentValidation *bool - Comment interface{} + Comment any Ordered *bool // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any @@ -110,7 +110,7 @@ func (imo *InsertManyOptionsBuilder) SetBypassDocumentValidation(b bool) *Insert // SetComment sets the value for the Comment field. Specifies a string or document that will be // included in server logs, profiling logs, and currentOp queries to help trace the operation. // The default value is nil, which means that no comment will be included in the logs. -func (imo *InsertManyOptionsBuilder) SetComment(comment interface{}) *InsertManyOptionsBuilder { +func (imo *InsertManyOptionsBuilder) SetComment(comment any) *InsertManyOptionsBuilder { imo.Opts = append(imo.Opts, func(opts *InsertManyOptions) error { opts.Comment = comment diff --git a/mongo/options/loggeroptions.go b/mongo/options/loggeroptions.go index 3a5c0806ad..0eb7ce4217 100644 --- a/mongo/options/loggeroptions.go +++ b/mongo/options/loggeroptions.go @@ -63,10 +63,10 @@ type LogSink interface { // // "Level V(0) is the default, and logger.V(0).Info() has the same // meaning as logger.Info()." - Info(level int, message string, keysAndValues ...interface{}) + Info(level int, message string, keysAndValues ...any) // Error logs an error message with the given key/value pairs - Error(err error, message string, keysAndValues ...interface{}) + Error(err error, message string, keysAndValues ...any) } // LoggerOptions represent arguments used to configure Logging in the Go Driver. diff --git a/mongo/options/replaceoptions.go b/mongo/options/replaceoptions.go index 8b6c7e166d..794a77eb9c 100644 --- a/mongo/options/replaceoptions.go +++ b/mongo/options/replaceoptions.go @@ -15,11 +15,11 @@ import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" type ReplaceOptions struct { BypassDocumentValidation *bool Collation *Collation - Comment interface{} - Hint interface{} + Comment any + Hint any Upsert *bool - Let interface{} - Sort interface{} + Let any + Sort any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -73,7 +73,7 @@ func (ro *ReplaceOptionsBuilder) SetCollation(c *Collation) *ReplaceOptionsBuild // SetComment sets the value for the Comment field. Specifies a string or document that will // be included in server logs, profiling logs, and currentOp queries to help trace the operation. // The default value is nil, which means that no comment will be included in the logs. -func (ro *ReplaceOptionsBuilder) SetComment(comment interface{}) *ReplaceOptionsBuilder { +func (ro *ReplaceOptionsBuilder) SetComment(comment any) *ReplaceOptionsBuilder { ro.Opts = append(ro.Opts, func(opts *ReplaceOptions) error { opts.Comment = comment @@ -91,7 +91,7 @@ func (ro *ReplaceOptionsBuilder) SetComment(comment interface{}) *ReplaceOptions // 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 (ro *ReplaceOptionsBuilder) SetHint(h interface{}) *ReplaceOptionsBuilder { +func (ro *ReplaceOptionsBuilder) SetHint(h any) *ReplaceOptionsBuilder { ro.Opts = append(ro.Opts, func(opts *ReplaceOptions) error { opts.Hint = h @@ -118,7 +118,7 @@ func (ro *ReplaceOptionsBuilder) SetUpsert(b bool) *ReplaceOptionsBuilder { // for using this option. This must be a document mapping parameter names to values. Values // must be constant or closed expressions that do not reference document fields. Parameters // can then be accessed as variables in an aggregate expression context (e.g. "$$var"). -func (ro *ReplaceOptionsBuilder) SetLet(l interface{}) *ReplaceOptionsBuilder { +func (ro *ReplaceOptionsBuilder) SetLet(l any) *ReplaceOptionsBuilder { ro.Opts = append(ro.Opts, func(opts *ReplaceOptions) error { opts.Let = l @@ -133,7 +133,7 @@ func (ro *ReplaceOptionsBuilder) SetLet(l interface{}) *ReplaceOptionsBuilder { // set, the first document in the sorted 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 (ro *ReplaceOptionsBuilder) SetSort(s interface{}) *ReplaceOptionsBuilder { +func (ro *ReplaceOptionsBuilder) SetSort(s any) *ReplaceOptionsBuilder { ro.Opts = append(ro.Opts, func(opts *ReplaceOptions) error { opts.Sort = s diff --git a/mongo/options/rewrapdatakeyoptions.go b/mongo/options/rewrapdatakeyoptions.go index 08d5bfc1e8..3dab855f3a 100644 --- a/mongo/options/rewrapdatakeyoptions.go +++ b/mongo/options/rewrapdatakeyoptions.go @@ -12,7 +12,7 @@ package options // See corresponding setter methods for documentation. type RewrapManyDataKeyOptions struct { Provider *string - MasterKey interface{} + MasterKey any } // RewrapManyDataKeyOptionsBuilder contains options to configure rewraping a @@ -46,7 +46,7 @@ func (rmdko *RewrapManyDataKeyOptionsBuilder) SetProvider(provider string) *Rewr // SetMasterKey sets the value for the MasterKey field. MasterKey identifies the new masterKey. // If omitted, rewraps with the current masterKey. -func (rmdko *RewrapManyDataKeyOptionsBuilder) SetMasterKey(masterKey interface{}) *RewrapManyDataKeyOptionsBuilder { +func (rmdko *RewrapManyDataKeyOptionsBuilder) SetMasterKey(masterKey any) *RewrapManyDataKeyOptionsBuilder { rmdko.Opts = append(rmdko.Opts, func(opts *RewrapManyDataKeyOptions) error { opts.MasterKey = masterKey diff --git a/mongo/options/updateoptions.go b/mongo/options/updateoptions.go index 2a9f4f48d0..c5d15b7a15 100644 --- a/mongo/options/updateoptions.go +++ b/mongo/options/updateoptions.go @@ -13,14 +13,14 @@ import "go.mongodb.org/mongo-driver/v2/internal/optionsutil" // // See corresponding setter methods for documentation. type UpdateOneOptions struct { - ArrayFilters []interface{} + ArrayFilters []any BypassDocumentValidation *bool Collation *Collation - Comment interface{} - Hint interface{} + Comment any + Hint any Upsert *bool - Let interface{} - Sort interface{} + Let any + Sort any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -48,7 +48,7 @@ func (uo *UpdateOneOptionsBuilder) List() []func(*UpdateOneOptions) error { // set of filters specifying to which array elements an update should apply. The // default value is nil, which means the update will apply to all array // elements. -func (uo *UpdateOneOptionsBuilder) SetArrayFilters(af []interface{}) *UpdateOneOptionsBuilder { +func (uo *UpdateOneOptionsBuilder) SetArrayFilters(af []any) *UpdateOneOptionsBuilder { uo.Opts = append(uo.Opts, func(opts *UpdateOneOptions) error { opts.ArrayFilters = af @@ -88,7 +88,7 @@ func (uo *UpdateOneOptionsBuilder) SetCollation(c *Collation) *UpdateOneOptionsB // SetComment sets the value for the Comment field. Specifies a string or document that will be // included in server logs, profiling logs, and currentOp queries to help trace the operation. // The default value is nil, which means that no comment will be included in the logs. -func (uo *UpdateOneOptionsBuilder) SetComment(comment interface{}) *UpdateOneOptionsBuilder { +func (uo *UpdateOneOptionsBuilder) SetComment(comment any) *UpdateOneOptionsBuilder { uo.Opts = append(uo.Opts, func(opts *UpdateOneOptions) error { opts.Comment = comment @@ -106,7 +106,7 @@ func (uo *UpdateOneOptionsBuilder) SetComment(comment interface{}) *UpdateOneOpt // 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 (uo *UpdateOneOptionsBuilder) SetHint(h interface{}) *UpdateOneOptionsBuilder { +func (uo *UpdateOneOptionsBuilder) SetHint(h any) *UpdateOneOptionsBuilder { uo.Opts = append(uo.Opts, func(opts *UpdateOneOptions) error { opts.Hint = h @@ -133,7 +133,7 @@ func (uo *UpdateOneOptionsBuilder) SetUpsert(b bool) *UpdateOneOptionsBuilder { // this option. This must be a document mapping parameter names to values. Values must be constant // or closed expressions that do not reference document fields. Parameters can then be accessed // as variables in an aggregate expression context (e.g. "$$var"). -func (uo *UpdateOneOptionsBuilder) SetLet(l interface{}) *UpdateOneOptionsBuilder { +func (uo *UpdateOneOptionsBuilder) SetLet(l any) *UpdateOneOptionsBuilder { uo.Opts = append(uo.Opts, func(opts *UpdateOneOptions) error { opts.Let = l @@ -148,7 +148,7 @@ func (uo *UpdateOneOptionsBuilder) SetLet(l interface{}) *UpdateOneOptionsBuilde // set, the first document in the sorted 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 (uo *UpdateOneOptionsBuilder) SetSort(s interface{}) *UpdateOneOptionsBuilder { +func (uo *UpdateOneOptionsBuilder) SetSort(s any) *UpdateOneOptionsBuilder { uo.Opts = append(uo.Opts, func(opts *UpdateOneOptions) error { opts.Sort = s @@ -163,13 +163,13 @@ func (uo *UpdateOneOptionsBuilder) SetSort(s interface{}) *UpdateOneOptionsBuild // // See corresponding setter methods for documentation. type UpdateManyOptions struct { - ArrayFilters []interface{} + ArrayFilters []any BypassDocumentValidation *bool Collation *Collation - Comment interface{} - Hint interface{} + Comment any + Hint any Upsert *bool - Let interface{} + Let any // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any // release. @@ -197,7 +197,7 @@ func (uo *UpdateManyOptionsBuilder) List() []func(*UpdateManyOptions) error { // set of filters specifying to which array elements an update should apply. The // default value is nil, which means the update will apply to all array // elements. -func (uo *UpdateManyOptionsBuilder) SetArrayFilters(af []interface{}) *UpdateManyOptionsBuilder { +func (uo *UpdateManyOptionsBuilder) SetArrayFilters(af []any) *UpdateManyOptionsBuilder { uo.Opts = append(uo.Opts, func(opts *UpdateManyOptions) error { opts.ArrayFilters = af @@ -237,7 +237,7 @@ func (uo *UpdateManyOptionsBuilder) SetCollation(c *Collation) *UpdateManyOption // SetComment sets the value for the Comment field. Specifies a string or document that will be // included in server logs, profiling logs, and currentOp queries to help trace the operation. // The default value is nil, which means that no comment will be included in the logs. -func (uo *UpdateManyOptionsBuilder) SetComment(comment interface{}) *UpdateManyOptionsBuilder { +func (uo *UpdateManyOptionsBuilder) SetComment(comment any) *UpdateManyOptionsBuilder { uo.Opts = append(uo.Opts, func(opts *UpdateManyOptions) error { opts.Comment = comment @@ -255,7 +255,7 @@ func (uo *UpdateManyOptionsBuilder) SetComment(comment interface{}) *UpdateManyO // 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 (uo *UpdateManyOptionsBuilder) SetHint(h interface{}) *UpdateManyOptionsBuilder { +func (uo *UpdateManyOptionsBuilder) SetHint(h any) *UpdateManyOptionsBuilder { uo.Opts = append(uo.Opts, func(opts *UpdateManyOptions) error { opts.Hint = h @@ -282,7 +282,7 @@ func (uo *UpdateManyOptionsBuilder) SetUpsert(b bool) *UpdateManyOptionsBuilder // this option. This must be a document mapping parameter names to values. Values must be constant // or closed expressions that do not reference document fields. Parameters can then be accessed // as variables in an aggregate expression context (e.g. "$$var"). -func (uo *UpdateManyOptionsBuilder) SetLet(l interface{}) *UpdateManyOptionsBuilder { +func (uo *UpdateManyOptionsBuilder) SetLet(l any) *UpdateManyOptionsBuilder { uo.Opts = append(uo.Opts, func(opts *UpdateManyOptions) error { opts.Let = l diff --git a/mongo/results.go b/mongo/results.go index 0a10dbaffe..e50157e6da 100644 --- a/mongo/results.go +++ b/mongo/results.go @@ -50,14 +50,14 @@ type ClientBulkWriteResult struct { // ClientBulkWriteInsertResult is the result type returned by a client-level bulk write of InsertOne operation. type ClientBulkWriteInsertResult struct { // The _id of the inserted document. A value generated by the driver will be of type primitive.ObjectID. - InsertedID interface{} + InsertedID any } // ClientBulkWriteUpdateResult is the result type returned from a client-level bulk write of UpdateOne, UpdateMany, and ReplaceOne operation. type ClientBulkWriteUpdateResult struct { - MatchedCount int64 // The number of documents matched by the filter. - ModifiedCount int64 // The number of documents modified by the operation. - UpsertedID interface{} // The _id field of the upserted document, or nil if no upsert was done. + MatchedCount int64 // The number of documents matched by the filter. + ModifiedCount int64 // The number of documents modified by the operation. + UpsertedID any // The _id field of the upserted document, or nil if no upsert was done. } // ClientBulkWriteDeleteResult is the result type returned by a client-level bulk write DeleteOne and DeleteMany operation. @@ -83,7 +83,7 @@ type BulkWriteResult struct { UpsertedCount int64 // A map of operation index to the _id of each upserted document. - UpsertedIDs map[int64]interface{} + UpsertedIDs map[int64]any // Operation performed with an acknowledged write. Values for other fields may // not be deterministic if the write operation was unacknowledged. @@ -93,7 +93,7 @@ type BulkWriteResult struct { // InsertOneResult is the result type returned by an InsertOne operation. type InsertOneResult struct { // The _id of the inserted document. A value generated by the driver will be of type bson.ObjectID. - InsertedID interface{} + InsertedID any // Operation performed with an acknowledged write. Values for other fields may // not be deterministic if the write operation was unacknowledged. @@ -103,7 +103,7 @@ type InsertOneResult struct { // InsertManyResult is a result type returned by an InsertMany operation. type InsertManyResult struct { // The _id values of the inserted documents. Values generated by the driver will be of type bson.ObjectID. - InsertedIDs []interface{} + InsertedIDs []any // Operation performed with an acknowledged write. Values for other fields may // not be deterministic if the write operation was unacknowledged. @@ -159,10 +159,10 @@ type DatabaseSpecification struct { // UpdateResult is the result type returned from UpdateOne, UpdateMany, and ReplaceOne operations. type UpdateResult struct { - MatchedCount int64 // The number of documents matched by the filter. - ModifiedCount int64 // The number of documents modified by the operation. - UpsertedCount int64 // The number of documents upserted by the operation. - UpsertedID interface{} // The _id field of the upserted document, or nil if no upsert was done. + MatchedCount int64 // The number of documents matched by the filter. + ModifiedCount int64 // The number of documents modified by the operation. + UpsertedCount int64 // The number of documents upserted by the operation. + UpsertedID any // The _id field of the upserted document, or nil if no upsert was done. // Operation performed with an acknowledged write. Values for other fields may // not be deterministic if the write operation was unacknowledged. diff --git a/mongo/search_index_view.go b/mongo/search_index_view.go index d0e1007051..5df3b8fb4e 100644 --- a/mongo/search_index_view.go +++ b/mongo/search_index_view.go @@ -37,7 +37,7 @@ type SearchIndexView struct { type SearchIndexModel struct { // A document describing the definition for the search index. It cannot be nil. // See https://www.mongodb.com/docs/atlas/atlas-search/create-index/ for reference. - Definition interface{} + Definition any // The search index options. Options *options.SearchIndexesOptionsBuilder @@ -250,7 +250,7 @@ func (siv SearchIndexView) DropOne( func (siv SearchIndexView) UpdateOne( ctx context.Context, name string, - definition interface{}, + definition any, _ ...options.Lister[options.UpdateSearchIndexOptions], ) error { if definition == nil { diff --git a/mongo/session.go b/mongo/session.go index 8ff0de56d1..db08f12589 100644 --- a/mongo/session.go +++ b/mongo/session.go @@ -126,9 +126,9 @@ func (s *Session) EndSession(ctx context.Context) { // see the Client.StartSession method documentation. func (s *Session) WithTransaction( ctx context.Context, - fn func(ctx context.Context) (interface{}, error), + fn func(ctx context.Context) (any, error), opts ...options.Lister[options.TransactionOptions], -) (interface{}, error) { +) (any, error) { timeout := time.NewTimer(withTransactionTimeout) defer timeout.Stop() var err error diff --git a/mongo/single_result.go b/mongo/single_result.go index 40b5a5c58b..5cae298462 100644 --- a/mongo/single_result.go +++ b/mongo/single_result.go @@ -41,7 +41,7 @@ type SingleResult struct { // // The document parameter must be a non-nil document. func NewSingleResultFromDocument( - document interface{}, + document any, err error, registry *bson.Registry, ) *SingleResult { @@ -52,7 +52,7 @@ func NewSingleResultFromDocument( registry = defaultRegistry } - cur, createErr := NewCursorFromDocuments([]interface{}{document}, err, registry) + cur, createErr := NewCursorFromDocuments([]any{document}, err, registry) if createErr != nil { return &SingleResult{err: createErr} } @@ -70,7 +70,7 @@ func NewSingleResultFromDocument( // // If the operation was successful and returned a document, Decode will return any errors from the unmarshalling process // without any modification. If v is nil or is a typed nil, an error will be returned. -func (sr *SingleResult) Decode(v interface{}) error { +func (sr *SingleResult) Decode(v any) error { if sr.err != nil { return sr.err } diff --git a/mongo/with_transactions_test.go b/mongo/with_transactions_test.go index 0a74f9deeb..9bdcff5305 100644 --- a/mongo/with_transactions_test.go +++ b/mongo/with_transactions_test.go @@ -78,7 +78,7 @@ func TestConvenientTransactions(t *testing.T) { defer sess.EndSession(context.Background()) testErr := errors.New("test error") - _, err = sess.WithTransaction(context.Background(), func(context.Context) (interface{}, error) { + _, err = sess.WithTransaction(context.Background(), func(context.Context) (any, error) { return nil, testErr }) assert.Equal(t, testErr, err, "expected error %v, got %v", testErr, err) @@ -92,7 +92,7 @@ func TestConvenientTransactions(t *testing.T) { assert.Nil(t, err, "StartSession error: %v", err) defer sess.EndSession(context.Background()) - res, err := sess.WithTransaction(context.Background(), func(context.Context) (interface{}, error) { + res, err := sess.WithTransaction(context.Background(), func(context.Context) (any, error) { return false, nil }) assert.Nil(t, err, "WithTransaction error: %v", err) @@ -112,7 +112,7 @@ func TestConvenientTransactions(t *testing.T) { assert.Nil(t, err, "StartSession error: %v", err) defer sess.EndSession(context.Background()) - _, err = sess.WithTransaction(context.Background(), func(context.Context) (interface{}, error) { + _, err = sess.WithTransaction(context.Background(), func(context.Context) (any, error) { return nil, CommandError{Name: "test Error", Labels: []string{driver.TransientTransactionError}} }) assert.NotNil(t, err, "expected WithTransaction error, got nil") @@ -144,7 +144,7 @@ func TestConvenientTransactions(t *testing.T) { assert.Nil(t, err, "StartSession error: %v", err) defer sess.EndSession(context.Background()) - _, err = sess.WithTransaction(context.Background(), func(ctx context.Context) (interface{}, error) { + _, err = sess.WithTransaction(context.Background(), func(ctx context.Context) (any, error) { _, err := coll.InsertOne(ctx, bson.D{{"x", 1}}) return nil, err }) @@ -177,7 +177,7 @@ func TestConvenientTransactions(t *testing.T) { assert.Nil(t, err, "StartSession error: %v", err) defer sess.EndSession(context.Background()) - _, err = sess.WithTransaction(context.Background(), func(ctx context.Context) (interface{}, error) { + _, err = sess.WithTransaction(context.Background(), func(ctx context.Context) (any, error) { _, err := coll.InsertOne(ctx, bson.D{{"x", 1}}) return nil, err }) @@ -242,7 +242,7 @@ func TestConvenientTransactions(t *testing.T) { // insert succeeds, it cancels the Context created above and returns a non-retryable error, which forces // WithTransaction to abort the txn. callbackErr := errors.New("error") - callback := func(ctx context.Context) (interface{}, error) { + callback := func(ctx context.Context) (any, error) { _, err = coll.InsertOne(ctx, bson.D{{"x", 1}}) if err != nil { return nil, err @@ -404,7 +404,7 @@ func TestConvenientTransactions(t *testing.T) { // "commitTransaction" can be sent. callback := func() bool { transactionCtx, cancel := context.WithCancel(context.Background()) - _, _ = sess.WithTransaction(transactionCtx, func(ctx context.Context) (interface{}, error) { + _, _ = sess.WithTransaction(transactionCtx, func(ctx context.Context) (any, error) { _, err := coll.InsertOne(ctx, bson.M{"x": 1}) assert.NoError(t, err, "InsertOne error: %v", err) cancel() @@ -433,7 +433,7 @@ func TestConvenientTransactions(t *testing.T) { // returnError tracks whether or not the callback is being retried returnError := true - res, err := sess.WithTransaction(context.Background(), func(context.Context) (interface{}, error) { + res, err := sess.WithTransaction(context.Background(), func(context.Context) (any, error) { if returnError { returnError = false return nil, fmt.Errorf("%w", @@ -471,7 +471,7 @@ func TestConvenientTransactions(t *testing.T) { withTransactionContext, cancel := context.WithTimeout(context.Background(), time.Nanosecond) defer cancel() - _, _ = sess.WithTransaction(withTransactionContext, func(ctx context.Context) (interface{}, error) { + _, _ = sess.WithTransaction(withTransactionContext, func(ctx context.Context) (any, error) { _, err := coll.InsertOne(ctx, bson.D{{}}) return nil, err }) @@ -506,7 +506,7 @@ func TestConvenientTransactions(t *testing.T) { withTransactionContext, cancel := context.WithTimeout(context.Background(), 2*time.Second) cancel() - _, _ = sess.WithTransaction(withTransactionContext, func(ctx context.Context) (interface{}, error) { + _, _ = sess.WithTransaction(withTransactionContext, func(ctx context.Context) (any, error) { _, err := coll.InsertOne(ctx, bson.D{{}}) return nil, err }) @@ -558,7 +558,7 @@ func TestConvenientTransactions(t *testing.T) { defer sess.EndSession(context.Background()) callback := func() bool { - _, err = sess.WithTransaction(context.Background(), func(ctx context.Context) (interface{}, error) { + _, err = sess.WithTransaction(context.Background(), func(ctx context.Context) (any, error) { // Set a timeout of 300ms to cause a timeout on first insertOne // and force a retry. c, cancel := context.WithTimeout(ctx, 300*time.Millisecond) @@ -587,7 +587,7 @@ func TestConvenientTransactions(t *testing.T) { defer sess.EndSession(context.Background()) count := 0 - _, _ = sess.WithTransaction(context.Background(), func(context.Context) (interface{}, error) { + _, _ = sess.WithTransaction(context.Background(), func(context.Context) (any, error) { count++ time.Sleep(10 * time.Millisecond) diff --git a/mongo/writeconcern/writeconcern.go b/mongo/writeconcern/writeconcern.go index 00e60e1c1b..208f230ef0 100644 --- a/mongo/writeconcern/writeconcern.go +++ b/mongo/writeconcern/writeconcern.go @@ -36,7 +36,7 @@ type WriteConcern struct { // // For more information about the "w" option, see // https://www.mongodb.com/docs/manual/reference/write-concern/#w-option - W interface{} + W any // Journal requests acknowledgment from MongoDB that the write operation has // been written to the on-disk journal. It sets the "j" option in a MongoDB