Skip to content

Commit e4e5820

Browse files
committed
WIP
1 parent dd94409 commit e4e5820

File tree

9 files changed

+147
-8
lines changed

9 files changed

+147
-8
lines changed

internal/integration/unified/collection_operation_execution.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
231231

232232
var keys bson.Raw
233233
indexOpts := options.Index()
234+
opts := options.CreateIndexes()
234235

235236
elems, err := operation.Arguments.Elements()
236237
if err != nil {
@@ -285,6 +286,8 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
285286
indexOpts.SetWeights(val.Document())
286287
case "wildcardProjection":
287288
indexOpts.SetWildcardProjection(val.Document())
289+
case "rawData":
290+
opts.SetRawData(val.Boolean())
288291
default:
289292
return nil, fmt.Errorf("unrecognized createIndex option %q", key)
290293
}
@@ -297,7 +300,8 @@ func executeCreateIndex(ctx context.Context, operation *operation) (*operationRe
297300
Keys: keys,
298301
Options: indexOpts,
299302
}
300-
name, err := coll.Indexes().CreateOne(ctx, model)
303+
304+
name, err := coll.Indexes().CreateOne(ctx, model, opts)
301305
return newValueResult(bson.TypeString, bsoncore.AppendString(nil, name), err), nil
302306
}
303307

@@ -605,6 +609,8 @@ func executeDropIndex(ctx context.Context, operation *operation) (*operationResu
605609
// ensured an analogue exists, extend "skippedTestDescriptions" to avoid
606610
// this error.
607611
return nil, fmt.Errorf("the maxTimeMS collection option is not supported")
612+
case "rawData":
613+
dropIndexOpts.SetRawData(val.Boolean())
608614
default:
609615
return nil, fmt.Errorf("unrecognized dropIndex option %q", key)
610616
}
@@ -1180,6 +1186,8 @@ func executeListIndexes(ctx context.Context, operation *operation) (*operationRe
11801186
switch key {
11811187
case "batchSize":
11821188
opts.SetBatchSize(val.Int32())
1189+
case "rawData":
1190+
opts.SetRawData(val.Boolean())
11831191
default:
11841192
return nil, fmt.Errorf("unrecognized listIndexes option: %q", key)
11851193
}

mongo/database.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ func (db *Database) ListCollections(
487487
if args.AuthorizedCollections != nil {
488488
op = op.AuthorizedCollections(*args.AuthorizedCollections)
489489
}
490+
if args.RawData != nil {
491+
op = op.RawData(*args.RawData)
492+
}
490493

491494
retry := driver.RetryNone
492495
if db.client.retryReads {

mongo/index_view.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ func (iv IndexView) List(ctx context.Context, opts ...options.Lister[options.Lis
101101
op = op.BatchSize(*args.BatchSize)
102102
cursorOpts.BatchSize = *args.BatchSize
103103
}
104+
if args.RawData != nil {
105+
op = op.RawData(*args.RawData)
106+
}
104107

105108
retry := driver.RetryNone
106109
if iv.coll.client.retryReads {
@@ -279,6 +282,9 @@ func (iv IndexView) CreateMany(
279282

280283
op.CommitQuorum(commitQuorum)
281284
}
285+
if args.RawData != nil {
286+
op = op.RawData(*args.RawData)
287+
}
282288

283289
_, err = processWriteError(op.Execute(ctx))
284290
if err != nil {
@@ -376,7 +382,12 @@ func (iv IndexView) createOptionsDoc(opts options.Lister[options.IndexOptions])
376382
return optsDoc, nil
377383
}
378384

379-
func (iv IndexView) drop(ctx context.Context, index any, _ ...options.Lister[options.DropIndexesOptions]) error {
385+
func (iv IndexView) drop(ctx context.Context, index any, opts ...options.Lister[options.DropIndexesOptions]) error {
386+
args, err := mongoutil.NewOptions[options.DropIndexesOptions](opts...)
387+
if err != nil {
388+
return fmt.Errorf("failed to construct options from builder: %w", err)
389+
}
390+
380391
if ctx == nil {
381392
ctx = context.Background()
382393
}
@@ -387,7 +398,7 @@ func (iv IndexView) drop(ctx context.Context, index any, _ ...options.Lister[opt
387398
defer sess.EndSession()
388399
}
389400

390-
err := iv.coll.client.validSession(sess)
401+
err = iv.coll.client.validSession(sess)
391402
if err != nil {
392403
return err
393404
}
@@ -408,6 +419,10 @@ func (iv IndexView) drop(ctx context.Context, index any, _ ...options.Lister[opt
408419
Deployment(iv.coll.client.deployment).ServerAPI(iv.coll.client.serverAPI).
409420
Timeout(iv.coll.client.timeout).Crypt(iv.coll.client.cryptFLE).Authenticator(iv.coll.client.authenticator)
410421

422+
if args.RawData != nil {
423+
op = op.RawData(*args.RawData)
424+
}
425+
411426
err = op.Execute(ctx)
412427
if err != nil {
413428
return replaceErrors(err)

mongo/options/indexoptions.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ package options
1212
// See corresponding setter methods for documentation.
1313
type CreateIndexesOptions struct {
1414
CommitQuorum interface{}
15+
RawData *bool
1516
}
1617

1718
// CreateIndexesOptionsBuilder contains options to create indexes. Each option
@@ -119,9 +120,23 @@ func (c *CreateIndexesOptionsBuilder) SetCommitQuorumVotingMembers() *CreateInde
119120
return c
120121
}
121122

123+
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
124+
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
125+
func (c *CreateIndexesOptionsBuilder) SetRawData(rawData bool) *CreateIndexesOptionsBuilder {
126+
c.Opts = append(c.Opts, func(opts *CreateIndexesOptions) error {
127+
opts.RawData = &rawData
128+
129+
return nil
130+
})
131+
132+
return c
133+
}
134+
122135
// DropIndexesOptions represents arguments that can be used to configure
123136
// IndexView.DropOne and IndexView.DropAll operations.
124-
type DropIndexesOptions struct{}
137+
type DropIndexesOptions struct {
138+
RawData *bool
139+
}
125140

126141
// DropIndexesOptionsBuilder contains options to configure dropping indexes.
127142
// Each option can be set through setter functions. See documentation for each
@@ -140,12 +155,25 @@ func (d *DropIndexesOptionsBuilder) List() []func(*DropIndexesOptions) error {
140155
return d.Opts
141156
}
142157

158+
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
159+
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
160+
func (d *DropIndexesOptionsBuilder) SetRawData(rawData bool) *DropIndexesOptionsBuilder {
161+
d.Opts = append(d.Opts, func(opts *DropIndexesOptions) error {
162+
opts.RawData = &rawData
163+
164+
return nil
165+
})
166+
167+
return d
168+
}
169+
143170
// ListIndexesOptions represents arguments that can be used to configure an
144171
// IndexView.List operation.
145172
//
146173
// See corresponding setter methods for documentation.
147174
type ListIndexesOptions struct {
148175
BatchSize *int32
176+
RawData *bool
149177
}
150178

151179
// ListIndexesOptionsBuilder contains options to configure count operations. Each
@@ -177,6 +205,18 @@ func (l *ListIndexesOptionsBuilder) SetBatchSize(i int32) *ListIndexesOptionsBui
177205
return l
178206
}
179207

208+
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
209+
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
210+
func (l *ListIndexesOptionsBuilder) SetRawData(rawData bool) *ListIndexesOptionsBuilder {
211+
l.Opts = append(l.Opts, func(opts *ListIndexesOptions) error {
212+
opts.RawData = &rawData
213+
214+
return nil
215+
})
216+
217+
return l
218+
}
219+
180220
// IndexOptions represents arguments that can be used to configure a new index
181221
// created through the IndexView.CreateOne or IndexView.CreateMany operations.
182222
//

mongo/options/listcollectionsoptions.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type ListCollectionsOptions struct {
1414
NameOnly *bool
1515
BatchSize *int32
1616
AuthorizedCollections *bool
17+
RawData *bool
1718
}
1819

1920
// ListCollectionsOptionsBuilder contains options to configure list collection
@@ -70,3 +71,15 @@ func (lc *ListCollectionsOptionsBuilder) SetAuthorizedCollections(b bool) *ListC
7071

7172
return lc
7273
}
74+
75+
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
76+
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
77+
func (lc *ListCollectionsOptionsBuilder) SetRawData(rawData bool) *ListCollectionsOptionsBuilder {
78+
lc.Opts = append(lc.Opts, func(opts *ListCollectionsOptions) error {
79+
opts.RawData = &rawData
80+
81+
return nil
82+
})
83+
84+
return lc
85+
}

x/mongo/driver/operation/create_indexes.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type CreateIndexes struct {
3838
result CreateIndexesResult
3939
serverAPI *driver.ServerAPIOptions
4040
timeout *time.Duration
41+
rawData *bool
4142
}
4243

4344
// CreateIndexesResult represents a createIndexes result returned by the server.
@@ -133,6 +134,10 @@ func (ci *CreateIndexes) command(dst []byte, desc description.SelectedServer) ([
133134
if ci.indexes != nil {
134135
dst = bsoncore.AppendArrayElement(dst, "indexes", ci.indexes)
135136
}
137+
// Set rawData for 8.2+ servers.
138+
if ci.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) {
139+
dst = bsoncore.AppendBooleanElement(dst, "rawData", *ci.rawData)
140+
}
136141
return dst, nil
137142
}
138143

@@ -277,3 +282,13 @@ func (ci *CreateIndexes) Authenticator(authenticator driver.Authenticator) *Crea
277282
ci.authenticator = authenticator
278283
return ci
279284
}
285+
286+
// RawData sets the rawData to access timeseries data in the compressed format.
287+
func (ci *CreateIndexes) RawData(rawData bool) *CreateIndexes {
288+
if ci == nil {
289+
ci = new(CreateIndexes)
290+
}
291+
292+
ci.rawData = &rawData
293+
return ci
294+
}

x/mongo/driver/operation/drop_indexes.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type DropIndexes struct {
3737
result DropIndexesResult
3838
serverAPI *driver.ServerAPIOptions
3939
timeout *time.Duration
40+
rawData *bool
4041
}
4142

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

105106
}
106107

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

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

119124
return dst, nil
120125
}
@@ -248,3 +253,13 @@ func (di *DropIndexes) Authenticator(authenticator driver.Authenticator) *DropIn
248253
di.authenticator = authenticator
249254
return di
250255
}
256+
257+
// RawData sets the rawData to access timeseries data in the compressed format.
258+
func (di *DropIndexes) RawData(rawData bool) *DropIndexes {
259+
if di == nil {
260+
di = new(DropIndexes)
261+
}
262+
263+
di.rawData = &rawData
264+
return di
265+
}

x/mongo/driver/operation/list_collections.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type ListCollections struct {
3939
batchSize *int32
4040
serverAPI *driver.ServerAPIOptions
4141
timeout *time.Duration
42+
rawData *bool
4243
}
4344

4445
// NewListCollections constructs and returns a new ListCollections.
@@ -92,7 +93,7 @@ func (lc *ListCollections) Execute(ctx context.Context) error {
9293

9394
}
9495

95-
func (lc *ListCollections) command(dst []byte, _ description.SelectedServer) ([]byte, error) {
96+
func (lc *ListCollections) command(dst []byte, desc description.SelectedServer) ([]byte, error) {
9697
dst = bsoncore.AppendInt32Element(dst, "listCollections", 1)
9798
if lc.filter != nil {
9899
dst = bsoncore.AppendDocumentElement(dst, "filter", lc.filter)
@@ -110,6 +111,11 @@ func (lc *ListCollections) command(dst []byte, _ description.SelectedServer) ([]
110111
}
111112
dst = bsoncore.AppendDocumentElement(dst, "cursor", cursorDoc.Build())
112113

114+
// Set rawData for 8.2+ servers.
115+
if lc.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) {
116+
dst = bsoncore.AppendBooleanElement(dst, "rawData", *lc.rawData)
117+
}
118+
113119
return dst, nil
114120
}
115121

@@ -274,3 +280,13 @@ func (lc *ListCollections) Authenticator(authenticator driver.Authenticator) *Li
274280
lc.authenticator = authenticator
275281
return lc
276282
}
283+
284+
// RawData sets the rawData to access timeseries data in the compressed format.
285+
func (lc *ListCollections) RawData(rawData bool) *ListCollections {
286+
if lc == nil {
287+
lc = new(ListCollections)
288+
}
289+
290+
lc.rawData = &rawData
291+
return lc
292+
}

x/mongo/driver/operation/list_indexes.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type ListIndexes struct {
3434
crypt driver.Crypt
3535
serverAPI *driver.ServerAPIOptions
3636
timeout *time.Duration
37+
rawData *bool
3738

3839
result driver.CursorResponse
3940
}
@@ -91,16 +92,19 @@ func (li *ListIndexes) Execute(ctx context.Context) error {
9192

9293
}
9394

94-
func (li *ListIndexes) command(dst []byte, _ description.SelectedServer) ([]byte, error) {
95+
func (li *ListIndexes) command(dst []byte, desc description.SelectedServer) ([]byte, error) {
9596
dst = bsoncore.AppendStringElement(dst, "listIndexes", li.collection)
9697
cursorIdx, cursorDoc := bsoncore.AppendDocumentStart(nil)
9798

9899
if li.batchSize != nil {
99-
100100
cursorDoc = bsoncore.AppendInt32Element(cursorDoc, "batchSize", *li.batchSize)
101101
}
102102
cursorDoc, _ = bsoncore.AppendDocumentEnd(cursorDoc, cursorIdx)
103103
dst = bsoncore.AppendDocumentElement(dst, "cursor", cursorDoc)
104+
// Set rawData for 8.2+ servers.
105+
if li.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) {
106+
dst = bsoncore.AppendBooleanElement(dst, "rawData", *li.rawData)
107+
}
104108

105109
return dst, nil
106110
}
@@ -235,3 +239,13 @@ func (li *ListIndexes) Authenticator(authenticator driver.Authenticator) *ListIn
235239
li.authenticator = authenticator
236240
return li
237241
}
242+
243+
// RawData sets the rawData to access timeseries data in the compressed format.
244+
func (li *ListIndexes) RawData(rawData bool) *ListIndexes {
245+
if li == nil {
246+
li = new(ListIndexes)
247+
}
248+
249+
li.rawData = &rawData
250+
return li
251+
}

0 commit comments

Comments
 (0)