Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
16 changes: 16 additions & 0 deletions internal/integration/unified/collection_operation_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func executeAggregate(ctx context.Context, operation *operation) (*operationResu
pipeline = bsonutil.RawToInterfaces(bsonutil.RawArrayToDocuments(val.Array())...)
case "let":
opts.SetLet(val.Document())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized aggregate option %q", key)
}
Expand Down Expand Up @@ -202,6 +204,8 @@ func executeCountDocuments(ctx context.Context, operation *operation) (*operatio
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
case "skip":
opts.SetSkip(int64(val.Int32()))
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized countDocuments option %q", key)
}
Expand Down Expand Up @@ -433,6 +437,8 @@ func executeDeleteOne(ctx context.Context, operation *operation) (*operationResu
opts.SetHint(hint)
case "let":
opts.SetLet(val.Document())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized deleteOne option %q", key)
}
Expand Down Expand Up @@ -487,6 +493,8 @@ func executeDeleteMany(ctx context.Context, operation *operation) (*operationRes
opts.SetHint(hint)
case "let":
opts.SetLet(val.Document())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized deleteMany option %q", key)
}
Expand Down Expand Up @@ -545,6 +553,8 @@ func executeDistinct(ctx context.Context, operation *operation) (*operationResul
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
// this error.
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized distinct option %q", key)
}
Expand Down Expand Up @@ -690,6 +700,8 @@ func executeEstimatedDocumentCount(ctx context.Context, operation *operation) (*
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
// this error.
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized estimatedDocumentCount option %q", key)
}
Expand Down Expand Up @@ -1062,6 +1074,8 @@ func executeInsertMany(ctx context.Context, operation *operation) (*operationRes
documents = bsonutil.RawToInterfaces(bsonutil.RawArrayToDocuments(val.Array())...)
case "ordered":
opts.SetOrdered(val.Boolean())
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized insertMany option %q", key)
}
Expand Down Expand Up @@ -1112,6 +1126,8 @@ func executeInsertOne(ctx context.Context, operation *operation) (*operationResu
opts.SetBypassDocumentValidation(val.Boolean())
case "comment":
opts.SetComment(val)
case "rawData":
opts.SetRawData(val.Boolean())
default:
return nil, fmt.Errorf("unrecognized insertOne option %q", key)
}
Expand Down
22 changes: 22 additions & 0 deletions mongo/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ func (coll *Collection) insert(
if args.Ordered != nil {
op = op.Ordered(*args.Ordered)
}
if args.RawData != nil {
op = op.RawData(*args.RawData)
}
retry := driver.RetryNone
if coll.client.retryWrites {
retry = driver.RetryOncePerCommand
Expand Down Expand Up @@ -375,6 +378,9 @@ func (coll *Collection) InsertOne(ctx context.Context, document interface{},
if args.Comment != nil {
imOpts.SetComment(args.Comment)
}
if args.RawData != nil {
imOpts = imOpts.SetRawData(*args.RawData)
}
res, err := coll.insert(ctx, []interface{}{document}, imOpts)

rr, err := processWriteError(err)
Expand Down Expand Up @@ -534,6 +540,9 @@ func (coll *Collection) delete(
}
op = op.Let(let)
}
if args.RawData != nil {
op = op.RawData(*args.RawData)
}

// deleteMany cannot be retried
retryMode := driver.RetryNone
Expand Down Expand Up @@ -575,6 +584,7 @@ func (coll *Collection) DeleteOne(
Comment: args.Comment,
Hint: args.Hint,
Let: args.Let,
RawData: args.RawData,
}

return coll.delete(ctx, filter, true, rrOne, deleteOptions)
Expand Down Expand Up @@ -1036,6 +1046,9 @@ func aggregate(a aggregateParams, opts ...options.Lister[options.AggregateOption
}
op.CustomOptions(customOptions)
}
if args.RawData != nil {
op = op.RawData(*args.RawData)
}

retry := driver.RetryNone
if a.retryRead && !hasOutputStage {
Expand Down Expand Up @@ -1124,6 +1137,9 @@ func (coll *Collection) CountDocuments(ctx context.Context, filter interface{},
}
op.Hint(hintVal)
}
if args.RawData != nil {
op = op.RawData(*args.RawData)
}
retry := driver.RetryNone
if coll.client.retryReads {
retry = driver.RetryOncePerCommand
Expand Down Expand Up @@ -1205,6 +1221,9 @@ func (coll *Collection) EstimatedDocumentCount(
}
op = op.Comment(comment)
}
if args.RawData != nil {
op = op.RawData(*args.RawData)
}

retry := driver.RetryNone
if coll.client.retryReads {
Expand Down Expand Up @@ -1294,6 +1313,9 @@ func (coll *Collection) Distinct(
}
op.Hint(hint)
}
if args.RawData != nil {
op = op.RawData(*args.RawData)
}
retry := driver.RetryNone
if coll.client.retryReads {
retry = driver.RetryOncePerCommand
Expand Down
13 changes: 13 additions & 0 deletions mongo/options/aggregateoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type AggregateOptions struct {
Hint interface{}
Let interface{}
Custom bson.M
RawData *bool
}

// AggregateOptionsBuilder contains options to configure aggregate operations.
Expand Down Expand Up @@ -163,3 +164,15 @@ func (ao *AggregateOptionsBuilder) SetCustom(c bson.M) *AggregateOptionsBuilder

return ao
}

// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a note that enabling it on pre-9.0 server versions has no effect. This applies for all SetRawData docs.

Note: This comment is irrelevant if we convert RawData into an internal-only option.

func (ao *AggregateOptionsBuilder) SetRawData(rawData bool) *AggregateOptionsBuilder {
ao.Opts = append(ao.Opts, func(opts *AggregateOptions) error {
opts.RawData = &rawData

return nil
})

return ao
}
13 changes: 13 additions & 0 deletions mongo/options/countoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type CountOptions struct {
Hint interface{}
Limit *int64
Skip *int64
RawData *bool
}

// CountOptionsBuilder contains options to configure count operations. Each
Expand Down Expand Up @@ -99,3 +100,15 @@ func (co *CountOptionsBuilder) SetSkip(i int64) *CountOptionsBuilder {

return co
}

// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
func (co *CountOptionsBuilder) SetRawData(rawData bool) *CountOptionsBuilder {
co.Opts = append(co.Opts, func(opts *CountOptions) error {
opts.RawData = &rawData

return nil
})

return co
}
26 changes: 26 additions & 0 deletions mongo/options/deleteoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type DeleteOneOptions struct {
Comment interface{}
Hint interface{}
Let interface{}
RawData *bool
}

// DeleteOneOptionsBuilder contains options to configure DeleteOne operations. Each
Expand Down Expand Up @@ -93,6 +94,18 @@ func (do *DeleteOneOptionsBuilder) SetLet(let interface{}) *DeleteOneOptionsBuil
return do
}

// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
func (do *DeleteOneOptionsBuilder) SetRawData(rawData bool) *DeleteOneOptionsBuilder {
do.Opts = append(do.Opts, func(opts *DeleteOneOptions) error {
opts.RawData = &rawData

return nil
})

return do
}

// DeleteManyOptions represents arguments that can be used to configure DeleteMany
// operations.
//
Expand All @@ -102,6 +115,7 @@ type DeleteManyOptions struct {
Comment interface{}
Hint interface{}
Let interface{}
RawData *bool
}

// DeleteManyOptionsBuilder contains options to configure DeleteMany operations.
Expand Down Expand Up @@ -179,3 +193,15 @@ func (do *DeleteManyOptionsBuilder) SetLet(let interface{}) *DeleteManyOptionsBu

return do
}

// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
func (do *DeleteManyOptionsBuilder) SetRawData(rawData bool) *DeleteManyOptionsBuilder {
do.Opts = append(do.Opts, func(opts *DeleteManyOptions) error {
opts.RawData = &rawData

return nil
})

return do
}
13 changes: 13 additions & 0 deletions mongo/options/distinctoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type DistinctOptions struct {
Collation *Collation
Comment interface{}
Hint interface{}
RawData *bool
}

// DistinctOptionsBuilder contains options to configure distinct operations. Each
Expand Down Expand Up @@ -77,3 +78,15 @@ func (do *DistinctOptionsBuilder) SetHint(hint interface{}) *DistinctOptionsBuil

return do
}

// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
func (do *DistinctOptionsBuilder) SetRawData(rawData bool) *DistinctOptionsBuilder {
do.Opts = append(do.Opts, func(opts *DistinctOptions) error {
opts.RawData = &rawData

return nil
})

return do
}
13 changes: 13 additions & 0 deletions mongo/options/estimatedcountoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package options
// See corresponding setter methods for documentation.
type EstimatedDocumentCountOptions struct {
Comment interface{}
RawData *bool
}

// EstimatedDocumentCountOptionsBuilder contains options to estimate document
Expand Down Expand Up @@ -44,3 +45,15 @@ func (eco *EstimatedDocumentCountOptionsBuilder) SetComment(comment interface{})

return eco
}

// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
func (eco *EstimatedDocumentCountOptionsBuilder) SetRawData(rawData bool) *EstimatedDocumentCountOptionsBuilder {
eco.Opts = append(eco.Opts, func(opts *EstimatedDocumentCountOptions) error {
opts.RawData = &rawData

return nil
})

return eco
}
26 changes: 26 additions & 0 deletions mongo/options/insertoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package options
type InsertOneOptions struct {
BypassDocumentValidation *bool
Comment interface{}
RawData *bool
}

// InsertOneOptionsBuilder represents functional options that configure an
Expand Down Expand Up @@ -53,6 +54,18 @@ func (ioo *InsertOneOptionsBuilder) SetComment(comment interface{}) *InsertOneOp
return ioo
}

// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
func (ioo *InsertOneOptionsBuilder) SetRawData(rawData bool) *InsertOneOptionsBuilder {
Copy link
Member

@prestonvasquez prestonvasquez Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the scope:

Customers do not need to be able to set this in their applications. The interface will be marked “for internal use only”.

It sounds like we should add this as a deprecated option to InsertOneOptions and add a SetInternalInsertOneOptions function to the xoptions package, rather than exposing an options-level setter. It sounds like nobody will use this but internal teams, we can pivot in the future if necessary.

opts := options.InsertOne()
_ = xoptions.SetInternalInsertOneOptions(opts, "rawData", true)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the rawData option should be internal only. However, I doubt if it should be a client level option because it makes users to set up multiple clients to handle different scenario. IMO, for operation options following the Lister interface with a correlated "optionsBuilder" type, we can have a setter, for example:

// Deprecated: This function is for internal use only. It may be changed or removed in any release.
func (ao *AggregateOptionsBuilder) SetInternalOption(key string, option any) error

What are your thoughts?
cc: @matthewdale

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see an internal-only options pattern was added a few months ago: xoptions.SetInternalClientOptions. Can we extend that pattern for this use case?

Copy link
Collaborator Author

@qingyang-hu qingyang-hu Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing pattern for SetInternalClientOptions is meant for ClientOptions. I think that adding rawData directly as a client option will cause inconvenience in most use cases, such as when setting an option for a specific operation.

Another option would be like xoptions.SetInternalAggregateOptions(opts *AggregateOptionsBuilder, key string, option any) error. We add a setter method for each OptionsBuilder in the xoptions package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qingyang-hu This sounds correct:

We add a setter method for each OptionsBuilder in the xoptions package.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there are two good options based on the existing pattern of SetInternalClientOptions. I prefer the first one because it can be extended to support future internal options without any additional API changes. Does that sound reasonable?

Custom key/value pairs with xoptions setter

Add a Custom optionsutil.Options field to every CRUD method options struct (like ClientOptions.Custom). Add a function to xoptions to set custom k/v pairs in Custom.

E.g.

package options

type FindOptions struct {
    // ...
    Custom optionsutil.Options
}
package xoptions

func SetFindOneCustom(f *options.FindOneOptionsBuilder, key string, option any) {
	f.Opts = append(f.Opts, func(opts *FindOneOptions) error {
		opts.Custom = optionsutil.WithValue(opts.Custom, key, option)
		return nil
	})
}

RawData bool option with xoptions setter

Add a RawData *bool field to every CRUD method options struct. Add a function to xoptions to set RawData for each supported option type.

E.g.

package options

type FindOptions struct {
    // ...
    RawData *bool
}
package xoptions

func SetFindOneRawData(f *options.FindOneOptionsBuilder, b bool) {
	f.Opts = append(f.Opts, func(opts *FindOneOptions) error {
		opts.RawData = &b
		return nil
	})
}

ioo.Opts = append(ioo.Opts, func(ioo *InsertOneOptions) error {
ioo.RawData = &rawData

return nil
})

return ioo
}

// InsertManyOptions represents arguments that can be used to configure an
// InsertMany operation.
//
Expand All @@ -61,6 +74,7 @@ type InsertManyOptions struct {
BypassDocumentValidation *bool
Comment interface{}
Ordered *bool
RawData *bool
}

// InsertManyOptionsBuilder contains options to configure insert operations.
Expand Down Expand Up @@ -121,3 +135,15 @@ func (imo *InsertManyOptionsBuilder) SetOrdered(b bool) *InsertManyOptionsBuilde

return imo
}

// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
func (imo *InsertManyOptionsBuilder) SetRawData(rawData bool) *InsertManyOptionsBuilder {
imo.Opts = append(imo.Opts, func(opts *InsertManyOptions) error {
opts.RawData = &rawData

return nil
})

return imo
}
15 changes: 15 additions & 0 deletions x/mongo/driver/operation/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Aggregate struct {
customOptions map[string]bsoncore.Value
timeout *time.Duration
omitMaxTimeMS bool
rawData *bool

result driver.CursorResponse
}
Expand Down Expand Up @@ -159,6 +160,10 @@ func (a *Aggregate) command(dst []byte, desc description.SelectedServer) ([]byte
if a.let != nil {
dst = bsoncore.AppendDocumentElement(dst, "let", a.let)
}
// Set rawData for 8.2+ servers.
if a.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) {
dst = bsoncore.AppendBooleanElement(dst, "rawData", *a.rawData)
}
for optionName, optionValue := range a.customOptions {
dst = bsoncore.AppendValueElement(dst, optionName, optionValue)
}
Expand Down Expand Up @@ -431,3 +436,13 @@ func (a *Aggregate) OmitMaxTimeMS(omit bool) *Aggregate {
a.omitMaxTimeMS = omit
return a
}

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

a.rawData = &rawData
return a
}
Loading
Loading