Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/integration/unified/client_operation_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
"go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/xoptions"
)

// This file contains helpers to execute client operations.
Expand Down Expand Up @@ -235,6 +236,11 @@ func executeClientBulkWrite(ctx context.Context, operation *operation) (*operati
return nil, err
}
opts.SetWriteConcern(c)
case "rawData":
err = xoptions.SetInternalClientBulkWriteOptions(opts, key, val.Boolean())
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unrecognized bulkWrite option %q", key)
}
Expand Down
19 changes: 18 additions & 1 deletion internal/integration/unified/collection_operation_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe

var keys bson.Raw
indexOpts := options.Index()
opts := options.CreateIndexes()

elems, err := operation.Arguments.Elements()
if err != nil {
Expand Down Expand Up @@ -295,6 +296,11 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
indexOpts.SetWeights(val.Document())
case "wildcardProjection":
indexOpts.SetWildcardProjection(val.Document())
case "rawData":
err = xoptions.SetInternalCreateIndexesOptions(opts, key, val.Boolean())
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unrecognized createIndex option %q", key)
}
Expand All @@ -307,7 +313,8 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
Keys: keys,
Options: indexOpts,
}
name, err := coll.Indexes().CreateOne(ctx, model)

name, err := coll.Indexes().CreateOne(ctx, model, opts)
return newValueResult(bson.TypeString, bsoncore.AppendString(nil, name), err), nil
}

Expand Down Expand Up @@ -624,6 +631,11 @@ func executeDropIndex(ctx context.Context, operation *operation) (*operationResu
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
// this error.
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
case "rawData":
err = xoptions.SetInternalDropIndexesOptions(dropIndexOpts, key, val.Boolean())
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unrecognized dropIndex option %q", key)
}
Expand Down Expand Up @@ -1217,6 +1229,11 @@ func executeListIndexes(ctx context.Context, operation *operation) (*operationRe
switch key {
case "batchSize":
opts.SetBatchSize(val.Int32())
case "rawData":
err = xoptions.SetInternalListIndexesOptions(opts, key, val.Boolean())
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unrecognized listIndexes option: %q", key)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/integration/unified/crud_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ func createListCollectionsArguments(args bson.Raw) (*listCollectionsArguments, e
lca.filter = val.Document()
case "nameOnly":
lca.opts.SetNameOnly(val.Boolean())
case "rawData":
err := xoptions.SetInternalListCollectionsOptions(lca.opts, key, val.Boolean())
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unrecognized listCollections option %q", key)
}
Expand Down
6 changes: 6 additions & 0 deletions mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"go.mongodb.org/mongo-driver/v2/internal/httputil"
"go.mongodb.org/mongo-driver/v2/internal/logger"
"go.mongodb.org/mongo-driver/v2/internal/mongoutil"
"go.mongodb.org/mongo-driver/v2/internal/optionsutil"
"go.mongodb.org/mongo-driver/v2/internal/ptrutil"
"go.mongodb.org/mongo-driver/v2/internal/serverselector"
"go.mongodb.org/mongo-driver/v2/internal/uuid"
Expand Down Expand Up @@ -957,6 +958,11 @@ func (c *Client) BulkWrite(ctx context.Context, writes []ClientBulkWrite,
selector: selector,
writeConcern: wc,
}
if rawDataOpt := optionsutil.Value(bwo.Internal, "rawData"); rawDataOpt != nil {
if rawData, ok := rawDataOpt.(bool); ok {
op.rawData = &rawData
}
}
if bwo.VerboseResults == nil || !(*bwo.VerboseResults) {
op.errorsOnly = true
} else if !acknowledged {
Expand Down
5 changes: 5 additions & 0 deletions mongo/client_bulk_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type clientBulkWrite struct {
client *Client
selector description.ServerSelector
writeConcern *writeconcern.WriteConcern
rawData *bool

result ClientBulkWriteResult
}
Expand Down Expand Up @@ -143,6 +144,10 @@ func (bw *clientBulkWrite) newCommand() func([]byte, description.SelectedServer)
}
dst = bsoncore.AppendDocumentElement(dst, "let", let)
}
// Set rawData for 8.2+ servers.
if bw.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) {
dst = bsoncore.AppendBooleanElement(dst, "rawData", *bw.rawData)
}
return dst, nil
}
}
Expand Down
6 changes: 6 additions & 0 deletions mongo/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"go.mongodb.org/mongo-driver/v2/internal/csfle"
"go.mongodb.org/mongo-driver/v2/internal/csot"
"go.mongodb.org/mongo-driver/v2/internal/mongoutil"
"go.mongodb.org/mongo-driver/v2/internal/optionsutil"
"go.mongodb.org/mongo-driver/v2/internal/serverselector"
"go.mongodb.org/mongo-driver/v2/mongo/options"
"go.mongodb.org/mongo-driver/v2/mongo/readconcern"
Expand Down Expand Up @@ -487,6 +488,11 @@ func (db *Database) ListCollections(
if args.AuthorizedCollections != nil {
op = op.AuthorizedCollections(*args.AuthorizedCollections)
}
if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil {
if rawData, ok := rawDataOpt.(bool); ok {
op = op.RawData(rawData)
}
}

retry := driver.RetryNone
if db.client.retryReads {
Expand Down
26 changes: 24 additions & 2 deletions mongo/index_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strconv"

"go.mongodb.org/mongo-driver/v2/internal/mongoutil"
"go.mongodb.org/mongo-driver/v2/internal/optionsutil"
"go.mongodb.org/mongo-driver/v2/internal/serverselector"
"go.mongodb.org/mongo-driver/v2/mongo/options"
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
Expand Down Expand Up @@ -101,6 +102,11 @@ func (iv IndexView) List(ctx context.Context, opts ...options.Lister[options.Lis
op = op.BatchSize(*args.BatchSize)
cursorOpts.BatchSize = *args.BatchSize
}
if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil {
if rawData, ok := rawDataOpt.(bool); ok {
op = op.RawData(rawData)
}
}

retry := driver.RetryNone
if iv.coll.client.retryReads {
Expand Down Expand Up @@ -279,6 +285,11 @@ func (iv IndexView) CreateMany(

op.CommitQuorum(commitQuorum)
}
if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil {
if rawData, ok := rawDataOpt.(bool); ok {
op = op.RawData(rawData)
}
}

_, err = processWriteError(op.Execute(ctx))
if err != nil {
Expand Down Expand Up @@ -376,7 +387,12 @@ func (iv IndexView) createOptionsDoc(opts options.Lister[options.IndexOptions])
return optsDoc, nil
}

func (iv IndexView) drop(ctx context.Context, index any, _ ...options.Lister[options.DropIndexesOptions]) error {
func (iv IndexView) drop(ctx context.Context, index any, opts ...options.Lister[options.DropIndexesOptions]) error {
args, err := mongoutil.NewOptions[options.DropIndexesOptions](opts...)
if err != nil {
return fmt.Errorf("failed to construct options from builder: %w", err)
}

if ctx == nil {
ctx = context.Background()
}
Expand All @@ -387,7 +403,7 @@ func (iv IndexView) drop(ctx context.Context, index any, _ ...options.Lister[opt
defer sess.EndSession()
}

err := iv.coll.client.validSession(sess)
err = iv.coll.client.validSession(sess)
if err != nil {
return err
}
Expand All @@ -408,6 +424,12 @@ func (iv IndexView) drop(ctx context.Context, index any, _ ...options.Lister[opt
Deployment(iv.coll.client.deployment).ServerAPI(iv.coll.client.serverAPI).
Timeout(iv.coll.client.timeout).Crypt(iv.coll.client.cryptFLE).Authenticator(iv.coll.client.authenticator)

if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil {
if rawData, ok := rawDataOpt.(bool); ok {
op = op.RawData(rawData)
}
}

err = op.Execute(ctx)
if err != nil {
return wrapErrors(err)
Expand Down
5 changes: 5 additions & 0 deletions mongo/options/clientbulkwriteoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package options

import (
"go.mongodb.org/mongo-driver/v2/internal/optionsutil"
"go.mongodb.org/mongo-driver/v2/mongo/writeconcern"
)

Expand All @@ -20,6 +21,10 @@ type ClientBulkWriteOptions struct {
Let interface{}
WriteConcern *writeconcern.WriteConcern
VerboseResults *bool

// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
// release.
Internal optionsutil.Options
}

// ClientBulkWriteOptionsBuilder contains options to configure client-level bulk
Expand Down
16 changes: 15 additions & 1 deletion mongo/options/indexoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@

package options

import "go.mongodb.org/mongo-driver/v2/internal/optionsutil"

// CreateIndexesOptions represents arguments that can be used to configure
// IndexView.CreateOne and IndexView.CreateMany operations.
//
// See corresponding setter methods for documentation.
type CreateIndexesOptions struct {
CommitQuorum interface{}

// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
// release.
Internal optionsutil.Options
}

// CreateIndexesOptionsBuilder contains options to create indexes. Each option
Expand Down Expand Up @@ -121,7 +127,11 @@ func (c *CreateIndexesOptionsBuilder) SetCommitQuorumVotingMembers() *CreateInde

// DropIndexesOptions represents arguments that can be used to configure
// IndexView.DropOne and IndexView.DropAll operations.
type DropIndexesOptions struct{}
type DropIndexesOptions struct {
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
// release.
Internal optionsutil.Options
}

// DropIndexesOptionsBuilder contains options to configure dropping indexes.
// Each option can be set through setter functions. See documentation for each
Expand All @@ -146,6 +156,10 @@ func (d *DropIndexesOptionsBuilder) List() []func(*DropIndexesOptions) error {
// See corresponding setter methods for documentation.
type ListIndexesOptions struct {
BatchSize *int32

// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
// release.
Internal optionsutil.Options
}

// ListIndexesOptionsBuilder contains options to configure count operations. Each
Expand Down
6 changes: 6 additions & 0 deletions mongo/options/listcollectionsoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package options

import "go.mongodb.org/mongo-driver/v2/internal/optionsutil"

// ListCollectionsOptions represents arguments that can be used to configure a
// ListCollections operation.
//
Expand All @@ -14,6 +16,10 @@ type ListCollectionsOptions struct {
NameOnly *bool
BatchSize *int32
AuthorizedCollections *bool

// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
// release.
Internal optionsutil.Options
}

// ListCollectionsOptionsBuilder contains options to configure list collection
Expand Down
15 changes: 15 additions & 0 deletions x/mongo/driver/operation/create_indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type CreateIndexes struct {
result CreateIndexesResult
serverAPI *driver.ServerAPIOptions
timeout *time.Duration
rawData *bool
}

// CreateIndexesResult represents a createIndexes result returned by the server.
Expand Down Expand Up @@ -133,6 +134,10 @@ func (ci *CreateIndexes) command(dst []byte, desc description.SelectedServer) ([
if ci.indexes != nil {
dst = bsoncore.AppendArrayElement(dst, "indexes", ci.indexes)
}
// Set rawData for 8.2+ servers.
if ci.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) {
dst = bsoncore.AppendBooleanElement(dst, "rawData", *ci.rawData)
}
return dst, nil
}

Expand Down Expand Up @@ -277,3 +282,13 @@ func (ci *CreateIndexes) Authenticator(authenticator driver.Authenticator) *Crea
ci.authenticator = authenticator
return ci
}

// RawData sets the rawData to access timeseries data in the compressed format.
func (ci *CreateIndexes) RawData(rawData bool) *CreateIndexes {
if ci == nil {
ci = new(CreateIndexes)
}

ci.rawData = &rawData
return ci
}
17 changes: 16 additions & 1 deletion x/mongo/driver/operation/drop_indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type DropIndexes struct {
result DropIndexesResult
serverAPI *driver.ServerAPIOptions
timeout *time.Duration
rawData *bool
}

// DropIndexesResult represents a dropIndexes result returned by the server.
Expand Down Expand Up @@ -104,7 +105,7 @@ func (di *DropIndexes) Execute(ctx context.Context) error {

}

func (di *DropIndexes) command(dst []byte, _ description.SelectedServer) ([]byte, error) {
func (di *DropIndexes) command(dst []byte, desc description.SelectedServer) ([]byte, error) {
dst = bsoncore.AppendStringElement(dst, "dropIndexes", di.collection)

switch t := di.index.(type) {
Expand All @@ -115,6 +116,10 @@ func (di *DropIndexes) command(dst []byte, _ description.SelectedServer) ([]byte
dst = bsoncore.AppendDocumentElement(dst, "index", t)
}
}
// Set rawData for 8.2+ servers.
if di.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) {
dst = bsoncore.AppendBooleanElement(dst, "rawData", *di.rawData)
}

return dst, nil
}
Expand Down Expand Up @@ -248,3 +253,13 @@ func (di *DropIndexes) Authenticator(authenticator driver.Authenticator) *DropIn
di.authenticator = authenticator
return di
}

// RawData sets the rawData to access timeseries data in the compressed format.
func (di *DropIndexes) RawData(rawData bool) *DropIndexes {
if di == nil {
di = new(DropIndexes)
}

di.rawData = &rawData
return di
}
Loading
Loading