Skip to content

Commit 503f3d3

Browse files
committed
add find/findAndModify
1 parent 53f0226 commit 503f3d3

File tree

6 files changed

+207
-9
lines changed

6 files changed

+207
-9
lines changed

internal/integration/unified/collection_operation_execution.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,11 @@ func executeFindOneAndDelete(ctx context.Context, operation *operation) (*operat
873873
opts.SetSort(val.Document())
874874
case "let":
875875
opts.SetLet(val.Document())
876+
case "rawData":
877+
err = xoptions.SetInternalFindOneAndDeleteOptions(opts, key, val.Boolean())
878+
if err != nil {
879+
return nil, err
880+
}
876881
default:
877882
return nil, fmt.Errorf("unrecognized findOneAndDelete option %q", key)
878883
}
@@ -955,6 +960,11 @@ func executeFindOneAndReplace(ctx context.Context, operation *operation) (*opera
955960
opts.SetSort(val.Document())
956961
case "upsert":
957962
opts.SetUpsert(val.Boolean())
963+
case "rawData":
964+
err = xoptions.SetInternalFindOneAndReplaceOptions(opts, key, val.Boolean())
965+
if err != nil {
966+
return nil, err
967+
}
958968
default:
959969
return nil, fmt.Errorf("unrecognized findOneAndReplace option %q", key)
960970
}
@@ -1047,6 +1057,11 @@ func executeFindOneAndUpdate(ctx context.Context, operation *operation) (*operat
10471057
}
10481058
case "upsert":
10491059
opts.SetUpsert(val.Boolean())
1060+
case "rawData":
1061+
err = xoptions.SetInternalFindOneAndUpdateOptions(opts, key, val.Boolean())
1062+
if err != nil {
1063+
return nil, err
1064+
}
10501065
default:
10511066
return nil, fmt.Errorf("unrecognized findOneAndUpdate option %q", key)
10521067
}
@@ -1541,6 +1556,11 @@ func createFindCursor(ctx context.Context, operation *operation) (*cursorResult,
15411556
case "maxAwaitTimeMS":
15421557
maxAwaitTimeMS := time.Duration(val.Int32()) * time.Millisecond
15431558
opts.SetMaxAwaitTime(maxAwaitTimeMS)
1559+
case "rawData":
1560+
err = xoptions.SetInternalFindOptions(opts, key, val.Boolean())
1561+
if err != nil {
1562+
return nil, err
1563+
}
15441564
default:
15451565
return nil, fmt.Errorf("unrecognized find option %q", key)
15461566
}

mongo/collection.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,11 @@ func (coll *Collection) find(
15361536
}
15371537
op.Sort(sort)
15381538
}
1539+
if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil {
1540+
if rawData, ok := rawDataOpt.(bool); ok {
1541+
op = op.RawData(rawData)
1542+
}
1543+
}
15391544
retry := driver.RetryNone
15401545
if coll.client.retryReads {
15411546
retry = driver.RetryOncePerCommand
@@ -1569,6 +1574,7 @@ func newFindArgsFromFindOneArgs(args *options.FindOneOptions) *options.FindOptio
15691574
v.ShowRecordID = args.ShowRecordID
15701575
v.Skip = args.Skip
15711576
v.Sort = args.Sort
1577+
v.Internal = args.Internal
15721578
}
15731579
return v
15741580
}
@@ -1731,6 +1737,11 @@ func (coll *Collection) FindOneAndDelete(
17311737
}
17321738
op = op.Let(let)
17331739
}
1740+
if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil {
1741+
if rawData, ok := rawDataOpt.(bool); ok {
1742+
op = op.RawData(rawData)
1743+
}
1744+
}
17341745

17351746
return coll.findAndModify(ctx, op)
17361747
}
@@ -1828,6 +1839,11 @@ func (coll *Collection) FindOneAndReplace(
18281839
}
18291840
op = op.Let(let)
18301841
}
1842+
if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil {
1843+
if rawData, ok := rawDataOpt.(bool); ok {
1844+
op = op.RawData(rawData)
1845+
}
1846+
}
18311847

18321848
return coll.findAndModify(ctx, op)
18331849
}
@@ -1937,6 +1953,11 @@ func (coll *Collection) FindOneAndUpdate(
19371953
}
19381954
op = op.Let(let)
19391955
}
1956+
if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil {
1957+
if rawData, ok := rawDataOpt.(bool); ok {
1958+
op = op.RawData(rawData)
1959+
}
1960+
}
19401961

19411962
return coll.findAndModify(ctx, op)
19421963
}

mongo/options/findoptions.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ package options
88

99
import (
1010
"time"
11+
12+
"go.mongodb.org/mongo-driver/v2/internal/optionsutil"
1113
)
1214

1315
// FindOptions represents arguments that can be used to configure a Find
@@ -35,6 +37,10 @@ type FindOptions struct {
3537
Let interface{}
3638
Limit *int64
3739
NoCursorTimeout *bool
40+
41+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
42+
// release.
43+
Internal optionsutil.Options
3844
}
3945

4046
// FindOptionsBuilder represents functional options that configure an Findopts.
@@ -285,6 +291,10 @@ type FindOneOptions struct {
285291
ShowRecordID *bool
286292
Skip *int64
287293
Sort interface{}
294+
295+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
296+
// release.
297+
Internal optionsutil.Options
288298
}
289299

290300
// FindOneOptionsBuilder represents functional options that configure an
@@ -450,6 +460,10 @@ type FindOneAndReplaceOptions struct {
450460
Upsert *bool
451461
Hint interface{}
452462
Let interface{}
463+
464+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
465+
// release.
466+
Internal optionsutil.Options
453467
}
454468

455469
// FindOneAndReplaceOptionsBuilder contains options to perform a findAndModify
@@ -611,6 +625,10 @@ type FindOneAndUpdateOptions struct {
611625
Upsert *bool
612626
Hint interface{}
613627
Let interface{}
628+
629+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
630+
// release.
631+
Internal optionsutil.Options
614632
}
615633

616634
// FindOneAndUpdateOptionsBuilder contains options to configure a
@@ -782,6 +800,10 @@ type FindOneAndDeleteOptions struct {
782800
Sort interface{}
783801
Hint interface{}
784802
Let interface{}
803+
804+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
805+
// release.
806+
Internal optionsutil.Options
785807
}
786808

787809
// FindOneAndDeleteOptionsBuilder contains options to configure delete

x/mongo/driver/operation/find.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type Find struct {
6161
result driver.CursorResponse
6262
serverAPI *driver.ServerAPIOptions
6363
timeout *time.Duration
64+
rawData *bool
6465
logger *logger.Logger
6566
omitMaxTimeMS bool
6667
}
@@ -191,6 +192,10 @@ func (f *Find) command(dst []byte, desc description.SelectedServer) ([]byte, err
191192
if f.tailable != nil {
192193
dst = bsoncore.AppendBooleanElement(dst, "tailable", *f.tailable)
193194
}
195+
// Set rawData for 8.2+ servers.
196+
if f.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) {
197+
dst = bsoncore.AppendBooleanElement(dst, "rawData", *f.rawData)
198+
}
194199
return dst, nil
195200
}
196201

@@ -565,6 +570,16 @@ func (f *Find) Authenticator(authenticator driver.Authenticator) *Find {
565570
return f
566571
}
567572

573+
// RawData sets the rawData to access timeseries data in the compressed format.
574+
func (f *Find) RawData(rawData bool) *Find {
575+
if f == nil {
576+
f = new(Find)
577+
}
578+
579+
f.rawData = &rawData
580+
return f
581+
}
582+
568583
// OmitMaxTimeMS omits the automatically-calculated "maxTimeMS" from the
569584
// command.
570585
func (f *Find) OmitMaxTimeMS(omit bool) *Find {

x/mongo/driver/operation/find_and_modify.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type FindAndModify struct {
5050
serverAPI *driver.ServerAPIOptions
5151
let bsoncore.Document
5252
timeout *time.Duration
53+
rawData *bool
5354

5455
result FindAndModifyResult
5556
}
@@ -211,6 +212,10 @@ func (fam *FindAndModify) command(dst []byte, desc description.SelectedServer) (
211212
if fam.let != nil {
212213
dst = bsoncore.AppendDocumentElement(dst, "let", fam.let)
213214
}
215+
// Set rawData for 8.2+ servers.
216+
if fam.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) {
217+
dst = bsoncore.AppendBooleanElement(dst, "rawData", *fam.rawData)
218+
}
214219

215220
return dst, nil
216221
}
@@ -476,3 +481,13 @@ func (fam *FindAndModify) Authenticator(authenticator driver.Authenticator) *Fin
476481
fam.authenticator = authenticator
477482
return fam
478483
}
484+
485+
// RawData sets the rawData to access timeseries data in the compressed format.
486+
func (fam *FindAndModify) RawData(rawData bool) *FindAndModify {
487+
if fam == nil {
488+
fam = new(FindAndModify)
489+
}
490+
491+
fam.rawData = &rawData
492+
return fam
493+
}

0 commit comments

Comments
 (0)