From f35a93aa0ece8ee7e5f98132479f3b339ae4631f Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Tue, 26 Sep 2023 11:27:26 -0400 Subject: [PATCH] WIP --- mongo/client_encryption.go | 26 +- mongo/collection.go | 263 +++++++++++- mongo/integration/collection_test.go | 6 - .../unified/collection_operation_execution.go | 4 - mongo/options/clientoptions.go | 9 - mongo/options/deleteoptions.go | 27 -- mongo/options/distinctoptions.go | 25 -- mongo/options/encryptoptions.go | 34 -- mongo/options/estimatedcountoptions.go | 22 - mongo/options/findoptions.go | 393 ------------------ x/mongo/driver/topology/topology_options.go | 7 - 11 files changed, 268 insertions(+), 548 deletions(-) diff --git a/mongo/client_encryption.go b/mongo/client_encryption.go index 564a1accaf..64a66349e1 100644 --- a/mongo/client_encryption.go +++ b/mongo/client_encryption.go @@ -211,7 +211,31 @@ func (ce *ClientEncryption) CreateDataKey(ctx context.Context, kmsProvider strin // transformExplicitEncryptionOptions creates explicit encryption options to be passed to libmongocrypt. func transformExplicitEncryptionOptions(opts ...*options.EncryptOptions) *mcopts.ExplicitEncryptionOptions { - eo := options.MergeEncryptOptions(opts...) + eo := options.Encrypt() + for _, opt := range opts { + if opt == nil { + continue + } + + if opt.KeyID != nil { + eo.KeyID = opt.KeyID + } + if opt.KeyAltName != nil { + eo.KeyAltName = opt.KeyAltName + } + if opt.Algorithm != "" { + eo.Algorithm = opt.Algorithm + } + if opt.QueryType != "" { + eo.QueryType = opt.QueryType + } + if opt.ContentionFactor != nil { + eo.ContentionFactor = opt.ContentionFactor + } + if opt.RangeOptions != nil { + eo.RangeOptions = opt.RangeOptions + } + } transformed := mcopts.ExplicitEncryption() if eo.KeyID != nil { transformed.SetKeyID(*eo.KeyID) diff --git a/mongo/collection.go b/mongo/collection.go index 319c50b998..9876665390 100644 --- a/mongo/collection.go +++ b/mongo/collection.go @@ -489,7 +489,26 @@ func (coll *Collection) delete(ctx context.Context, filter interface{}, deleteOn if deleteOne { limit = 1 } - do := options.MergeDeleteOptions(opts...) + + do := options.Delete() + for _, opt := range opts { + if opt == nil { + continue + } + if opt.Collation != nil { + do.Collation = opt.Collation + } + if opt.Comment != nil { + do.Comment = opt.Comment + } + if opt.Hint != nil { + do.Hint = opt.Hint + } + if opt.Let != nil { + do.Let = opt.Let + } + } + didx, doc := bsoncore.AppendDocumentStart(nil) doc = bsoncore.AppendDocumentElement(doc, "q", f) doc = bsoncore.AppendInt32Element(doc, "limit", limit) @@ -1170,8 +1189,18 @@ func (coll *Collection) EstimatedDocumentCount(ctx context.Context, rc = nil } - co := options.MergeEstimatedDocumentCountOptions(opts...) - + co := options.EstimatedDocumentCount() + for _, opt := range opts { + if opt == nil { + continue + } + if opt.Comment != nil { + co.Comment = opt.Comment + } + if opt.MaxTime != nil { + co.MaxTime = opt.MaxTime + } + } selector := makeReadPrefSelector(sess, coll.readSelector, coll.client.localThreshold) op := operation.NewCount().Session(sess).ClusterClock(coll.client.clock). Database(coll.db.name).Collection(coll.name).CommandMonitor(coll.client.monitor). @@ -1237,7 +1266,21 @@ func (coll *Collection) Distinct(ctx context.Context, fieldName string, filter i } selector := makeReadPrefSelector(sess, coll.readSelector, coll.client.localThreshold) - option := options.MergeDistinctOptions(opts...) + option := options.Distinct() + for _, do := range opts { + if do == nil { + continue + } + if do.Collation != nil { + option.Collation = do.Collation + } + if do.Comment != nil { + option.Comment = do.Comment + } + if do.MaxTime != nil { + option.MaxTime = do.MaxTime + } + } op := operation.NewDistinct(fieldName, f). Session(sess).ClusterClock(coll.client.clock). @@ -1290,6 +1333,75 @@ func (coll *Collection) Distinct(ctx context.Context, fieldName string, filter i return retArray, replaceErrors(err) } +// mergeFindOptions combines the given FindOptions instances into a single FindOptions in a last-one-wins fashion. +func mergeFindOptions(opts ...*options.FindOptions) *options.FindOptions { + fo := options.Find() + for _, opt := range opts { + if opt == nil { + continue + } + if opt.AllowDiskUse != nil { + fo.AllowDiskUse = opt.AllowDiskUse + } + if opt.AllowPartialResults != nil { + fo.AllowPartialResults = opt.AllowPartialResults + } + if opt.BatchSize != nil { + fo.BatchSize = opt.BatchSize + } + if opt.Collation != nil { + fo.Collation = opt.Collation + } + if opt.Comment != nil { + fo.Comment = opt.Comment + } + if opt.CursorType != nil { + fo.CursorType = opt.CursorType + } + if opt.Hint != nil { + fo.Hint = opt.Hint + } + if opt.Let != nil { + fo.Let = opt.Let + } + if opt.Limit != nil { + fo.Limit = opt.Limit + } + if opt.Max != nil { + fo.Max = opt.Max + } + if opt.MaxAwaitTime != nil { + fo.MaxAwaitTime = opt.MaxAwaitTime + } + if opt.MaxTime != nil { + fo.MaxTime = opt.MaxTime + } + if opt.Min != nil { + fo.Min = opt.Min + } + if opt.NoCursorTimeout != nil { + fo.NoCursorTimeout = opt.NoCursorTimeout + } + if opt.Projection != nil { + fo.Projection = opt.Projection + } + if opt.ReturnKey != nil { + fo.ReturnKey = opt.ReturnKey + } + if opt.ShowRecordID != nil { + fo.ShowRecordID = opt.ShowRecordID + } + if opt.Skip != nil { + fo.Skip = opt.Skip + } + if opt.Sort != nil { + fo.Sort = opt.Sort + } + } + + return fo +} + // Find executes a find command and returns a Cursor over the matching documents in the collection. // // The filter parameter must be a document containing query operators and can be used to select which documents are @@ -1331,7 +1443,7 @@ func (coll *Collection) Find(ctx context.Context, filter interface{}, rc = nil } - fo := options.MergeFindOptions(opts...) + fo := mergeFindOptions(opts...) selector := makeReadPrefSelector(sess, coll.readSelector, coll.client.localThreshold) op := operation.NewFind(f). @@ -1422,9 +1534,6 @@ func (coll *Collection) Find(ctx context.Context, filter interface{}, if fo.NoCursorTimeout != nil { op.NoCursorTimeout(*fo.NoCursorTimeout) } - if fo.OplogReplay != nil { - op.OplogReplay(*fo.OplogReplay) - } if fo.Projection != nil { proj, err := marshal(fo.Projection, coll.bsonOpts, coll.registry) if err != nil { @@ -1441,9 +1550,6 @@ func (coll *Collection) Find(ctx context.Context, filter interface{}, if fo.Skip != nil { op.Skip(*fo.Skip) } - if fo.Snapshot != nil { - op.Snapshot(*fo.Snapshot) - } if fo.Sort != nil { if isUnorderedMap(fo.Sort) { return nil, ErrMapForOrderedArgument{"sort"} @@ -1494,22 +1600,16 @@ func (coll *Collection) FindOne(ctx context.Context, filter interface{}, } findOpts = append(findOpts, &options.FindOptions{ AllowPartialResults: opt.AllowPartialResults, - BatchSize: opt.BatchSize, Collation: opt.Collation, Comment: opt.Comment, - CursorType: opt.CursorType, Hint: opt.Hint, Max: opt.Max, - MaxAwaitTime: opt.MaxAwaitTime, MaxTime: opt.MaxTime, Min: opt.Min, - NoCursorTimeout: opt.NoCursorTimeout, - OplogReplay: opt.OplogReplay, Projection: opt.Projection, ReturnKey: opt.ReturnKey, ShowRecordID: opt.ShowRecordID, Skip: opt.Skip, - Snapshot: opt.Snapshot, Sort: opt.Sort, }) } @@ -1583,6 +1683,40 @@ func (coll *Collection) findAndModify(ctx context.Context, op *operation.FindAnd } } +// mergeFindOneAndDeleteOptions combines the given FindOneAndDeleteOptions instances into a single +// FindOneAndDeleteOptions in a last-one-wins fashion. +func mergeFindOneAndDeleteOptions(opts ...*options.FindOneAndDeleteOptions) *options.FindOneAndDeleteOptions { + fo := options.FindOneAndDelete() + for _, opt := range opts { + if opt == nil { + continue + } + if opt.Collation != nil { + fo.Collation = opt.Collation + } + if opt.Comment != nil { + fo.Comment = opt.Comment + } + if opt.MaxTime != nil { + fo.MaxTime = opt.MaxTime + } + if opt.Projection != nil { + fo.Projection = opt.Projection + } + if opt.Sort != nil { + fo.Sort = opt.Sort + } + if opt.Hint != nil { + fo.Hint = opt.Hint + } + if opt.Let != nil { + fo.Let = opt.Let + } + } + + return fo +} + // FindOneAndDelete executes a findAndModify command to delete at most one document in the collection. and returns the // document as it appeared before deletion. // @@ -1601,7 +1735,7 @@ func (coll *Collection) FindOneAndDelete(ctx context.Context, filter interface{} if err != nil { return &SingleResult{err: err} } - fod := options.MergeFindOneAndDeleteOptions(opts...) + fod := mergeFindOneAndDeleteOptions(opts...) op := operation.NewFindAndModify(f).Remove(true).ServerAPI(coll.client.serverAPI).Timeout(coll.client.timeout). MaxTime(fod.MaxTime) if fod.Collation != nil { @@ -1652,6 +1786,49 @@ func (coll *Collection) FindOneAndDelete(ctx context.Context, filter interface{} return coll.findAndModify(ctx, op) } +// mergeFindOneAndReplaceOptions combines the given FindOneAndReplaceOptions instances into a single +// FindOneAndReplaceOptions in a last-one-wins fashion. +func mergeFindOneAndReplaceOptions(opts ...*options.FindOneAndReplaceOptions) *options.FindOneAndReplaceOptions { + fo := options.FindOneAndReplace() + for _, opt := range opts { + if opt == nil { + continue + } + if opt.BypassDocumentValidation != nil { + fo.BypassDocumentValidation = opt.BypassDocumentValidation + } + if opt.Collation != nil { + fo.Collation = opt.Collation + } + if opt.Comment != nil { + fo.Comment = opt.Comment + } + if opt.MaxTime != nil { + fo.MaxTime = opt.MaxTime + } + if opt.Projection != nil { + fo.Projection = opt.Projection + } + if opt.ReturnDocument != nil { + fo.ReturnDocument = opt.ReturnDocument + } + if opt.Sort != nil { + fo.Sort = opt.Sort + } + if opt.Upsert != nil { + fo.Upsert = opt.Upsert + } + if opt.Hint != nil { + fo.Hint = opt.Hint + } + if opt.Let != nil { + fo.Let = opt.Let + } + } + + return fo +} + // FindOneAndReplace executes a findAndModify command to replace at most one document in the collection // and returns the document as it appeared before replacement. // @@ -1681,7 +1858,7 @@ func (coll *Collection) FindOneAndReplace(ctx context.Context, filter interface{ return &SingleResult{err: errors.New("replacement document cannot contain keys beginning with '$'")} } - fo := options.MergeFindOneAndReplaceOptions(opts...) + fo := mergeFindOneAndReplaceOptions(opts...) op := operation.NewFindAndModify(f).Update(bsoncore.Value{Type: bsontype.EmbeddedDocument, Data: r}). ServerAPI(coll.client.serverAPI).Timeout(coll.client.timeout).MaxTime(fo.MaxTime) if fo.BypassDocumentValidation != nil && *fo.BypassDocumentValidation { @@ -1741,6 +1918,52 @@ func (coll *Collection) FindOneAndReplace(ctx context.Context, filter interface{ return coll.findAndModify(ctx, op) } +// mergeFindOneAndUpdateOptions combines the given FindOneAndUpdateOptions instances into a single +// FindOneAndUpdateOptions in a last-one-wins fashion. +func mergeFindOneAndUpdateOptions(opts ...*options.FindOneAndUpdateOptions) *options.FindOneAndUpdateOptions { + fo := options.FindOneAndUpdate() + for _, opt := range opts { + if opt == nil { + continue + } + if opt.ArrayFilters != nil { + fo.ArrayFilters = opt.ArrayFilters + } + if opt.BypassDocumentValidation != nil { + fo.BypassDocumentValidation = opt.BypassDocumentValidation + } + if opt.Collation != nil { + fo.Collation = opt.Collation + } + if opt.Comment != nil { + fo.Comment = opt.Comment + } + if opt.MaxTime != nil { + fo.MaxTime = opt.MaxTime + } + if opt.Projection != nil { + fo.Projection = opt.Projection + } + if opt.ReturnDocument != nil { + fo.ReturnDocument = opt.ReturnDocument + } + if opt.Sort != nil { + fo.Sort = opt.Sort + } + if opt.Upsert != nil { + fo.Upsert = opt.Upsert + } + if opt.Hint != nil { + fo.Hint = opt.Hint + } + if opt.Let != nil { + fo.Let = opt.Let + } + } + + return fo +} + // FindOneAndUpdate executes a findAndModify command to update at most one document in the collection and returns the // document as it appeared before updating. // @@ -1768,7 +1991,7 @@ func (coll *Collection) FindOneAndUpdate(ctx context.Context, filter interface{} return &SingleResult{err: err} } - fo := options.MergeFindOneAndUpdateOptions(opts...) + fo := mergeFindOneAndUpdateOptions(opts...) op := operation.NewFindAndModify(f).ServerAPI(coll.client.serverAPI).Timeout(coll.client.timeout). MaxTime(fo.MaxTime) diff --git a/mongo/integration/collection_test.go b/mongo/integration/collection_test.go index 4e7f24813d..16026cc520 100644 --- a/mongo/integration/collection_test.go +++ b/mongo/integration/collection_test.go @@ -1136,15 +1136,12 @@ func TestCollection(t *testing.T) { // SetCursorTime and setMaxAwaitTime will be deprecated in GODRIVER-1775 opts := options.FindOne(). SetAllowPartialResults(true). - SetBatchSize(2). SetCollation(&options.Collation{Locale: "en_US"}). SetComment(expectedComment). SetHint(indexName). SetMax(bson.D{{"x", int32(5)}}). SetMaxTime(1 * time.Second). SetMin(bson.D{{"x", int32(0)}}). - SetNoCursorTimeout(false). - SetOplogReplay(false). SetProjection(bson.D{{"x", int32(1)}}). SetReturnKey(false). SetShowRecordID(false). @@ -1161,15 +1158,12 @@ func TestCollection(t *testing.T) { optionsDoc := bsoncore.NewDocumentBuilder(). AppendBoolean("allowPartialResults", true). - AppendInt32("batchSize", 2). StartDocument("collation").AppendString("locale", "en_US").FinishDocument(). AppendString("comment", expectedComment). AppendString("hint", indexName). StartDocument("max").AppendInt32("x", 5).FinishDocument(). AppendInt32("maxTimeMS", 1000). StartDocument("min").AppendInt32("x", 0).FinishDocument(). - AppendBoolean("noCursorTimeout", false). - AppendBoolean("oplogReplay", false). StartDocument("projection").AppendInt32("x", 1).FinishDocument(). AppendBoolean("returnKey", false). AppendBoolean("showRecordId", false). diff --git a/mongo/integration/unified/collection_operation_execution.go b/mongo/integration/unified/collection_operation_execution.go index 18c6e040fe..510566624b 100644 --- a/mongo/integration/unified/collection_operation_execution.go +++ b/mongo/integration/unified/collection_operation_execution.go @@ -1233,8 +1233,6 @@ func createFindCursor(ctx context.Context, operation *operation) (*cursorResult, opts.SetMin(val.Document()) case "noCursorTimeout": opts.SetNoCursorTimeout(val.Boolean()) - case "oplogReplay": - opts.SetOplogReplay(val.Boolean()) case "projection": opts.SetProjection(val.Document()) case "returnKey": @@ -1243,8 +1241,6 @@ func createFindCursor(ctx context.Context, operation *operation) (*cursorResult, opts.SetShowRecordID(val.Boolean()) case "skip": opts.SetSkip(int64(val.Int32())) - case "snapshot": - opts.SetSnapshot(val.Boolean()) case "sort": opts.SetSort(val.Document()) default: diff --git a/mongo/options/clientoptions.go b/mongo/options/clientoptions.go index f014da418b..287164341f 100644 --- a/mongo/options/clientoptions.go +++ b/mongo/options/clientoptions.go @@ -219,12 +219,6 @@ type ClientOptions struct { uri string cs *connstring.ConnString - // AuthenticateToAnything skips server type checks when deciding if authentication is possible. - // - // Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any - // release. - AuthenticateToAnything *bool - // Crypt specifies a custom driver.Crypt to be used to encrypt and decrypt documents. The default is no // encryption. // @@ -984,9 +978,6 @@ func MergeClientOptions(opts ...*ClientOptions) *ClientOptions { if opt.Auth != nil { c.Auth = opt.Auth } - if opt.AuthenticateToAnything != nil { - c.AuthenticateToAnything = opt.AuthenticateToAnything - } if opt.Compressors != nil { c.Compressors = opt.Compressors } diff --git a/mongo/options/deleteoptions.go b/mongo/options/deleteoptions.go index 59aaef9153..f155b2a6c7 100644 --- a/mongo/options/deleteoptions.go +++ b/mongo/options/deleteoptions.go @@ -60,30 +60,3 @@ func (do *DeleteOptions) SetLet(let interface{}) *DeleteOptions { do.Let = let return do } - -// MergeDeleteOptions combines the given DeleteOptions instances into a single DeleteOptions in a last-one-wins fashion. -// -// Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a -// single options struct instead. -func MergeDeleteOptions(opts ...*DeleteOptions) *DeleteOptions { - dOpts := Delete() - for _, do := range opts { - if do == nil { - continue - } - if do.Collation != nil { - dOpts.Collation = do.Collation - } - if do.Comment != nil { - dOpts.Comment = do.Comment - } - if do.Hint != nil { - dOpts.Hint = do.Hint - } - if do.Let != nil { - dOpts.Let = do.Let - } - } - - return dOpts -} diff --git a/mongo/options/distinctoptions.go b/mongo/options/distinctoptions.go index 819f2a9a8f..4cfcb98526 100644 --- a/mongo/options/distinctoptions.go +++ b/mongo/options/distinctoptions.go @@ -54,28 +54,3 @@ func (do *DistinctOptions) SetMaxTime(d time.Duration) *DistinctOptions { do.MaxTime = &d return do } - -// MergeDistinctOptions combines the given DistinctOptions instances into a single DistinctOptions in a last-one-wins -// fashion. -// -// Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a -// single options struct instead. -func MergeDistinctOptions(opts ...*DistinctOptions) *DistinctOptions { - distinctOpts := Distinct() - for _, do := range opts { - if do == nil { - continue - } - if do.Collation != nil { - distinctOpts.Collation = do.Collation - } - if do.Comment != nil { - distinctOpts.Comment = do.Comment - } - if do.MaxTime != nil { - distinctOpts.MaxTime = do.MaxTime - } - } - - return distinctOpts -} diff --git a/mongo/options/encryptoptions.go b/mongo/options/encryptoptions.go index 88517d0c8d..c11a541916 100644 --- a/mongo/options/encryptoptions.go +++ b/mongo/options/encryptoptions.go @@ -115,37 +115,3 @@ func (ro *RangeOptions) SetPrecision(precision int32) *RangeOptions { ro.Precision = &precision return ro } - -// MergeEncryptOptions combines the argued EncryptOptions in a last-one wins fashion. -// -// Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a -// single options struct instead. -func MergeEncryptOptions(opts ...*EncryptOptions) *EncryptOptions { - eo := Encrypt() - for _, opt := range opts { - if opt == nil { - continue - } - - if opt.KeyID != nil { - eo.KeyID = opt.KeyID - } - if opt.KeyAltName != nil { - eo.KeyAltName = opt.KeyAltName - } - if opt.Algorithm != "" { - eo.Algorithm = opt.Algorithm - } - if opt.QueryType != "" { - eo.QueryType = opt.QueryType - } - if opt.ContentionFactor != nil { - eo.ContentionFactor = opt.ContentionFactor - } - if opt.RangeOptions != nil { - eo.RangeOptions = opt.RangeOptions - } - } - - return eo -} diff --git a/mongo/options/estimatedcountoptions.go b/mongo/options/estimatedcountoptions.go index d088af9c9a..b7d52bef6d 100644 --- a/mongo/options/estimatedcountoptions.go +++ b/mongo/options/estimatedcountoptions.go @@ -43,25 +43,3 @@ func (eco *EstimatedDocumentCountOptions) SetMaxTime(d time.Duration) *Estimated eco.MaxTime = &d return eco } - -// MergeEstimatedDocumentCountOptions combines the given EstimatedDocumentCountOptions instances into a single -// EstimatedDocumentCountOptions in a last-one-wins fashion. -// -// Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a -// single options struct instead. -func MergeEstimatedDocumentCountOptions(opts ...*EstimatedDocumentCountOptions) *EstimatedDocumentCountOptions { - e := EstimatedDocumentCount() - for _, opt := range opts { - if opt == nil { - continue - } - if opt.Comment != nil { - e.Comment = opt.Comment - } - if opt.MaxTime != nil { - e.MaxTime = opt.MaxTime - } - } - - return e -} diff --git a/mongo/options/findoptions.go b/mongo/options/findoptions.go index fa3bf1197a..93c4787e98 100644 --- a/mongo/options/findoptions.go +++ b/mongo/options/findoptions.go @@ -73,12 +73,6 @@ type FindOptions struct { // The default value is false. NoCursorTimeout *bool - // OplogReplay is for internal replication use only and should not be set. - // - // Deprecated: This option has been deprecated in MongoDB version 4.4 and will be ignored by the server if it is - // set. - OplogReplay *bool - // Project 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. Projection interface{} @@ -94,12 +88,6 @@ type FindOptions struct { // Skip is the number of documents to skip before adding documents to the result. The default value is 0. Skip *int64 - // Snapshot specifies whether the cursor will not return a document more than once because of an intervening write operation. - // The default value is false. - // - // Deprecated: This option has been deprecated in MongoDB version 3.6 and removed in MongoDB version 4.0. - Snapshot *bool - // Sort is a document specifying the order in which documents should be returned. The driver will return an error if the // sort parameter is a multi-key map. Sort interface{} @@ -204,14 +192,6 @@ func (f *FindOptions) SetNoCursorTimeout(b bool) *FindOptions { return f } -// SetOplogReplay sets the value for the OplogReplay field. -// -// Deprecated: This option has been deprecated in MongoDB version 4.4 and will be ignored by the server if it is set. -func (f *FindOptions) SetOplogReplay(b bool) *FindOptions { - f.OplogReplay = &b - return f -} - // SetProjection sets the value for the Projection field. func (f *FindOptions) SetProjection(projection interface{}) *FindOptions { f.Projection = projection @@ -236,109 +216,18 @@ func (f *FindOptions) SetSkip(i int64) *FindOptions { return f } -// SetSnapshot sets the value for the Snapshot field. -// -// Deprecated: This option has been deprecated in MongoDB version 3.6 and removed in MongoDB version 4.0. -func (f *FindOptions) SetSnapshot(b bool) *FindOptions { - f.Snapshot = &b - return f -} - // SetSort sets the value for the Sort field. func (f *FindOptions) SetSort(sort interface{}) *FindOptions { f.Sort = sort return f } -// MergeFindOptions combines the given FindOptions instances into a single FindOptions in a last-one-wins fashion. -// -// Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a -// single options struct instead. -func MergeFindOptions(opts ...*FindOptions) *FindOptions { - fo := Find() - for _, opt := range opts { - if opt == nil { - continue - } - if opt.AllowDiskUse != nil { - fo.AllowDiskUse = opt.AllowDiskUse - } - if opt.AllowPartialResults != nil { - fo.AllowPartialResults = opt.AllowPartialResults - } - if opt.BatchSize != nil { - fo.BatchSize = opt.BatchSize - } - if opt.Collation != nil { - fo.Collation = opt.Collation - } - if opt.Comment != nil { - fo.Comment = opt.Comment - } - if opt.CursorType != nil { - fo.CursorType = opt.CursorType - } - if opt.Hint != nil { - fo.Hint = opt.Hint - } - if opt.Let != nil { - fo.Let = opt.Let - } - if opt.Limit != nil { - fo.Limit = opt.Limit - } - if opt.Max != nil { - fo.Max = opt.Max - } - if opt.MaxAwaitTime != nil { - fo.MaxAwaitTime = opt.MaxAwaitTime - } - if opt.MaxTime != nil { - fo.MaxTime = opt.MaxTime - } - if opt.Min != nil { - fo.Min = opt.Min - } - if opt.NoCursorTimeout != nil { - fo.NoCursorTimeout = opt.NoCursorTimeout - } - if opt.OplogReplay != nil { - fo.OplogReplay = opt.OplogReplay - } - if opt.Projection != nil { - fo.Projection = opt.Projection - } - if opt.ReturnKey != nil { - fo.ReturnKey = opt.ReturnKey - } - if opt.ShowRecordID != nil { - fo.ShowRecordID = opt.ShowRecordID - } - if opt.Skip != nil { - fo.Skip = opt.Skip - } - if opt.Snapshot != nil { - fo.Snapshot = opt.Snapshot - } - if opt.Sort != nil { - fo.Sort = opt.Sort - } - } - - return fo -} - // FindOneOptions represents options that can be used to configure a FindOne operation. type FindOneOptions struct { // If true, an operation on a sharded cluster can return partial results if some shards are down rather than // returning an error. The default value is false. AllowPartialResults *bool - // The maximum number of documents to be included in each batch returned by the server. - // - // Deprecated: This option is not valid for a findOne operation, as no cursor is actually created. - BatchSize *int32 - // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The // default value is nil, which means the default collation of the collection will be used. @@ -348,12 +237,6 @@ type FindOneOptions struct { // The default is nil, which means that no comment will be included in the logs. Comment *string - // Specifies the type of cursor that should be created for the operation. The default is NonTailable, which means - // that the cursor will be closed by the server when the last batch of documents is retrieved. - // - // Deprecated: This option is not valid for a findOne operation, as no cursor is actually created. - CursorType *CursorType - // The index to use for the aggregation. 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. @@ -363,13 +246,6 @@ type FindOneOptions struct { // there is no maximum value. Max interface{} - // The maximum amount of time that the server should wait for new documents to satisfy a tailable cursor query. - // This option is only valid for tailable await cursors (see the CursorType option for more information) and - // MongoDB versions >= 3.2. For other cursor types or previous server versions, this option is ignored. - // - // Deprecated: This option is not valid for a findOne operation, as no cursor is actually created. - MaxAwaitTime *time.Duration - // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there // is no time limit for query execution. // @@ -382,18 +258,6 @@ type FindOneOptions struct { // there is no minimum value. Min interface{} - // If true, the cursor created by the operation will not timeout after a period of inactivity. The default value - // is false. - // - // Deprecated: This option is not valid for a findOne operation, as no cursor is actually created. - NoCursorTimeout *bool - - // This option is for internal replication use only and should not be set. - // - // Deprecated: This option has been deprecated in MongoDB version 4.4 and will be ignored by the server if it is - // set. - OplogReplay *bool - // 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. Projection interface{} @@ -409,12 +273,6 @@ type FindOneOptions struct { // The number of documents to skip before selecting the document to be returned. The default value is 0. Skip *int64 - // If true, the cursor will not return a document more than once because of an intervening write operation. The - // default value is false. - // - // Deprecated: This option has been deprecated in MongoDB version 3.6 and removed in MongoDB version 4.0. - Snapshot *bool - // A document specifying the sort order to apply to the query. The first document in the sorted order will be // returned. The driver will return an error if the sort parameter is a multi-key map. Sort interface{} @@ -431,14 +289,6 @@ func (f *FindOneOptions) SetAllowPartialResults(b bool) *FindOneOptions { return f } -// SetBatchSize sets the value for the BatchSize field. -// -// Deprecated: This option is not valid for a findOne operation, as no cursor is actually created. -func (f *FindOneOptions) SetBatchSize(i int32) *FindOneOptions { - f.BatchSize = &i - return f -} - // SetCollation sets the value for the Collation field. func (f *FindOneOptions) SetCollation(collation *Collation) *FindOneOptions { f.Collation = collation @@ -451,14 +301,6 @@ func (f *FindOneOptions) SetComment(comment string) *FindOneOptions { return f } -// SetCursorType sets the value for the CursorType field. -// -// Deprecated: This option is not valid for a findOne operation, as no cursor is actually created. -func (f *FindOneOptions) SetCursorType(ct CursorType) *FindOneOptions { - f.CursorType = &ct - return f -} - // SetHint sets the value for the Hint field. func (f *FindOneOptions) SetHint(hint interface{}) *FindOneOptions { f.Hint = hint @@ -471,14 +313,6 @@ func (f *FindOneOptions) SetMax(max interface{}) *FindOneOptions { return f } -// SetMaxAwaitTime sets the value for the MaxAwaitTime field. -// -// Deprecated: This option is not valid for a findOne operation, as no cursor is actually created. -func (f *FindOneOptions) SetMaxAwaitTime(d time.Duration) *FindOneOptions { - f.MaxAwaitTime = &d - return f -} - // SetMaxTime sets the value for the MaxTime field. // // NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout @@ -495,23 +329,6 @@ func (f *FindOneOptions) SetMin(min interface{}) *FindOneOptions { return f } -// SetNoCursorTimeout sets the value for the NoCursorTimeout field. -// -// Deprecated: This option is not valid for a findOne operation, as no cursor is actually created. -func (f *FindOneOptions) SetNoCursorTimeout(b bool) *FindOneOptions { - f.NoCursorTimeout = &b - return f -} - -// SetOplogReplay sets the value for the OplogReplay field. -// -// Deprecated: This option has been deprecated in MongoDB version 4.4 and will be ignored by the server if it is -// set. -func (f *FindOneOptions) SetOplogReplay(b bool) *FindOneOptions { - f.OplogReplay = &b - return f -} - // SetProjection sets the value for the Projection field. func (f *FindOneOptions) SetProjection(projection interface{}) *FindOneOptions { f.Projection = projection @@ -536,90 +353,12 @@ func (f *FindOneOptions) SetSkip(i int64) *FindOneOptions { return f } -// SetSnapshot sets the value for the Snapshot field. -// -// Deprecated: This option has been deprecated in MongoDB version 3.6 and removed in MongoDB version 4.0. -func (f *FindOneOptions) SetSnapshot(b bool) *FindOneOptions { - f.Snapshot = &b - return f -} - // SetSort sets the value for the Sort field. func (f *FindOneOptions) SetSort(sort interface{}) *FindOneOptions { f.Sort = sort return f } -// MergeFindOneOptions combines the given FindOneOptions instances into a single FindOneOptions in a last-one-wins -// fashion. -// -// Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a -// single options struct instead. -func MergeFindOneOptions(opts ...*FindOneOptions) *FindOneOptions { - fo := FindOne() - for _, opt := range opts { - if opt == nil { - continue - } - if opt.AllowPartialResults != nil { - fo.AllowPartialResults = opt.AllowPartialResults - } - if opt.BatchSize != nil { - fo.BatchSize = opt.BatchSize - } - if opt.Collation != nil { - fo.Collation = opt.Collation - } - if opt.Comment != nil { - fo.Comment = opt.Comment - } - if opt.CursorType != nil { - fo.CursorType = opt.CursorType - } - if opt.Hint != nil { - fo.Hint = opt.Hint - } - if opt.Max != nil { - fo.Max = opt.Max - } - if opt.MaxAwaitTime != nil { - fo.MaxAwaitTime = opt.MaxAwaitTime - } - if opt.MaxTime != nil { - fo.MaxTime = opt.MaxTime - } - if opt.Min != nil { - fo.Min = opt.Min - } - if opt.NoCursorTimeout != nil { - fo.NoCursorTimeout = opt.NoCursorTimeout - } - if opt.OplogReplay != nil { - fo.OplogReplay = opt.OplogReplay - } - if opt.Projection != nil { - fo.Projection = opt.Projection - } - if opt.ReturnKey != nil { - fo.ReturnKey = opt.ReturnKey - } - if opt.ShowRecordID != nil { - fo.ShowRecordID = opt.ShowRecordID - } - if opt.Skip != nil { - fo.Skip = opt.Skip - } - if opt.Snapshot != nil { - fo.Snapshot = opt.Snapshot - } - if opt.Sort != nil { - fo.Sort = opt.Sort - } - } - - return fo -} - // FindOneAndReplaceOptions represents options that can be used to configure a FindOneAndReplace instance. type FindOneAndReplaceOptions struct { // If true, writes executed as part of the operation will opt out of document-level validation on the server. This @@ -746,52 +485,6 @@ func (f *FindOneAndReplaceOptions) SetLet(let interface{}) *FindOneAndReplaceOpt return f } -// MergeFindOneAndReplaceOptions combines the given FindOneAndReplaceOptions instances into a single -// FindOneAndReplaceOptions in a last-one-wins fashion. -// -// Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a -// single options struct instead. -func MergeFindOneAndReplaceOptions(opts ...*FindOneAndReplaceOptions) *FindOneAndReplaceOptions { - fo := FindOneAndReplace() - for _, opt := range opts { - if opt == nil { - continue - } - if opt.BypassDocumentValidation != nil { - fo.BypassDocumentValidation = opt.BypassDocumentValidation - } - if opt.Collation != nil { - fo.Collation = opt.Collation - } - if opt.Comment != nil { - fo.Comment = opt.Comment - } - if opt.MaxTime != nil { - fo.MaxTime = opt.MaxTime - } - if opt.Projection != nil { - fo.Projection = opt.Projection - } - if opt.ReturnDocument != nil { - fo.ReturnDocument = opt.ReturnDocument - } - if opt.Sort != nil { - fo.Sort = opt.Sort - } - if opt.Upsert != nil { - fo.Upsert = opt.Upsert - } - if opt.Hint != nil { - fo.Hint = opt.Hint - } - if opt.Let != nil { - fo.Let = opt.Let - } - } - - return fo -} - // FindOneAndUpdateOptions represents options that can be used to configure a FindOneAndUpdate options. type FindOneAndUpdateOptions struct { // A set of filters specifying to which array elements an update should apply. This option is only valid for MongoDB @@ -929,55 +622,6 @@ func (f *FindOneAndUpdateOptions) SetLet(let interface{}) *FindOneAndUpdateOptio return f } -// MergeFindOneAndUpdateOptions combines the given FindOneAndUpdateOptions instances into a single -// FindOneAndUpdateOptions in a last-one-wins fashion. -// -// Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a -// single options struct instead. -func MergeFindOneAndUpdateOptions(opts ...*FindOneAndUpdateOptions) *FindOneAndUpdateOptions { - fo := FindOneAndUpdate() - for _, opt := range opts { - if opt == nil { - continue - } - if opt.ArrayFilters != nil { - fo.ArrayFilters = opt.ArrayFilters - } - if opt.BypassDocumentValidation != nil { - fo.BypassDocumentValidation = opt.BypassDocumentValidation - } - if opt.Collation != nil { - fo.Collation = opt.Collation - } - if opt.Comment != nil { - fo.Comment = opt.Comment - } - if opt.MaxTime != nil { - fo.MaxTime = opt.MaxTime - } - if opt.Projection != nil { - fo.Projection = opt.Projection - } - if opt.ReturnDocument != nil { - fo.ReturnDocument = opt.ReturnDocument - } - if opt.Sort != nil { - fo.Sort = opt.Sort - } - if opt.Upsert != nil { - fo.Upsert = opt.Upsert - } - if opt.Hint != nil { - fo.Hint = opt.Hint - } - if opt.Let != nil { - fo.Let = opt.Let - } - } - - return fo -} - // FindOneAndDeleteOptions represents options that can be used to configure a FindOneAndDelete operation. type FindOneAndDeleteOptions struct { // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB @@ -1071,40 +715,3 @@ func (f *FindOneAndDeleteOptions) SetLet(let interface{}) *FindOneAndDeleteOptio f.Let = let return f } - -// MergeFindOneAndDeleteOptions combines the given FindOneAndDeleteOptions instances into a single -// FindOneAndDeleteOptions in a last-one-wins fashion. -// -// Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a -// single options struct instead. -func MergeFindOneAndDeleteOptions(opts ...*FindOneAndDeleteOptions) *FindOneAndDeleteOptions { - fo := FindOneAndDelete() - for _, opt := range opts { - if opt == nil { - continue - } - if opt.Collation != nil { - fo.Collation = opt.Collation - } - if opt.Comment != nil { - fo.Comment = opt.Comment - } - if opt.MaxTime != nil { - fo.MaxTime = opt.MaxTime - } - if opt.Projection != nil { - fo.Projection = opt.Projection - } - if opt.Sort != nil { - fo.Sort = opt.Sort - } - if opt.Hint != nil { - fo.Hint = opt.Hint - } - if opt.Let != nil { - fo.Let = opt.Let - } - } - - return fo -} diff --git a/x/mongo/driver/topology/topology_options.go b/x/mongo/driver/topology/topology_options.go index 8deb614815..460b82e406 100644 --- a/x/mongo/driver/topology/topology_options.go +++ b/x/mongo/driver/topology/topology_options.go @@ -15,7 +15,6 @@ import ( "go.mongodb.org/mongo-driver/event" "go.mongodb.org/mongo-driver/internal/logger" - "go.mongodb.org/mongo-driver/mongo/description" "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/x/mongo/driver" "go.mongodb.org/mongo-driver/x/mongo/driver/auth" @@ -199,12 +198,6 @@ func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, // Required for SASL mechanism negotiation during handshake handshakeOpts.DBUser = cred.Source + "." + cred.Username } - if co.AuthenticateToAnything != nil && *co.AuthenticateToAnything { - // Authenticate arbiters - handshakeOpts.PerformAuthentication = func(serv description.Server) bool { - return true - } - } handshaker = func(driver.Handshaker) driver.Handshaker { return auth.Handshaker(nil, handshakeOpts)