Skip to content

Commit b1bb1fc

Browse files
committed
add delete
1 parent 547db1d commit b1bb1fc

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

mongo/collection.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ func (coll *Collection) delete(
534534
}
535535
op = op.Let(let)
536536
}
537+
if args.RawData != nil {
538+
op = op.RawData(*args.RawData)
539+
}
537540

538541
// deleteMany cannot be retried
539542
retryMode := driver.RetryNone
@@ -575,6 +578,7 @@ func (coll *Collection) DeleteOne(
575578
Comment: args.Comment,
576579
Hint: args.Hint,
577580
Let: args.Let,
581+
RawData: args.RawData,
578582
}
579583

580584
return coll.delete(ctx, filter, true, rrOne, deleteOptions)

mongo/options/deleteoptions.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type DeleteOneOptions struct {
1515
Comment interface{}
1616
Hint interface{}
1717
Let interface{}
18+
RawData *bool
1819
}
1920

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

97+
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
98+
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
99+
func (do *DeleteOneOptionsBuilder) SetRawData(rawData bool) *DeleteOneOptionsBuilder {
100+
do.Opts = append(do.Opts, func(opts *DeleteOneOptions) error {
101+
opts.RawData = &rawData
102+
103+
return nil
104+
})
105+
106+
return do
107+
}
108+
96109
// DeleteManyOptions represents arguments that can be used to configure DeleteMany
97110
// operations.
98111
//
@@ -102,6 +115,7 @@ type DeleteManyOptions struct {
102115
Comment interface{}
103116
Hint interface{}
104117
Let interface{}
118+
RawData *bool
105119
}
106120

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

180194
return do
181195
}
196+
197+
// SetRawData sets the value for the RawData field. If true, it allows the CRUD operations to access timeseries
198+
// collections on the bucket-level. This option is only valid for MongoDB versions >= 9.0. The default value is false.
199+
func (do *DeleteManyOptionsBuilder) SetRawData(rawData bool) *DeleteManyOptionsBuilder {
200+
do.Opts = append(do.Opts, func(opts *DeleteManyOptions) error {
201+
opts.RawData = &rawData
202+
203+
return nil
204+
})
205+
206+
return do
207+
}

x/mongo/driver/operation/delete.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type Delete struct {
4343
serverAPI *driver.ServerAPIOptions
4444
let bsoncore.Document
4545
timeout *time.Duration
46+
rawData *bool
4647
logger *logger.Logger
4748
}
4849

@@ -139,6 +140,10 @@ func (d *Delete) command(dst []byte, desc description.SelectedServer) ([]byte, e
139140
if d.let != nil {
140141
dst = bsoncore.AppendDocumentElement(dst, "let", d.let)
141142
}
143+
// Set rawData for 8.2+ servers.
144+
if d.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) {
145+
dst = bsoncore.AppendBooleanElement(dst, "rawData", *d.rawData)
146+
}
142147
return dst, nil
143148
}
144149

@@ -337,3 +342,13 @@ func (d *Delete) Authenticator(authenticator driver.Authenticator) *Delete {
337342
d.authenticator = authenticator
338343
return d
339344
}
345+
346+
// RawData sets the rawData to access timeseries data in the compressed format.
347+
func (d *Delete) RawData(rawData bool) *Delete {
348+
if d == nil {
349+
d = new(Delete)
350+
}
351+
352+
d.rawData = &rawData
353+
return d
354+
}

0 commit comments

Comments
 (0)