Skip to content

Commit 5cc147a

Browse files
committed
add listCollections
1 parent f420860 commit 5cc147a

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

internal/integration/unified/crud_helpers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ func createListCollectionsArguments(args bson.Raw) (*listCollectionsArguments, e
173173
lca.filter = val.Document()
174174
case "nameOnly":
175175
lca.opts.SetNameOnly(val.Boolean())
176+
case "rawData":
177+
lca.opts.SetRawData(val.Boolean())
176178
default:
177179
return nil, fmt.Errorf("unrecognized listCollections option %q", key)
178180
}

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/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/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+
}

0 commit comments

Comments
 (0)