Skip to content

Commit 48f45a6

Browse files
author
Divjot Arora
committed
Change ListCollections, ListIndexes, and ListDatabases to use CompositeSelector.
GODRIVER-735 Change-Id: Ic9627f5faa8249a860620642989dc2d292d97cd8
1 parent fe68735 commit 48f45a6

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

mongo/client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,14 @@ func (c *Client) ListDatabases(ctx context.Context, filter interface{}, opts ...
358358
Clock: c.clock,
359359
}
360360

361+
readSelector := description.CompositeSelector([]description.ServerSelector{
362+
description.ReadPrefSelector(readpref.Primary()),
363+
description.LatencySelector(c.localThreshold),
364+
})
361365
res, err := driver.ListDatabases(
362366
ctx, cmd,
363367
c.topology,
364-
description.ReadPrefSelector(readpref.Primary()),
368+
readSelector,
365369
c.id,
366370
c.topology.SessionPool,
367371
opts...,

mongo/database.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,14 @@ func (db *Database) ListCollections(ctx context.Context, filter interface{}, opt
233233
Clock: db.client.clock,
234234
}
235235

236+
readSelector := description.CompositeSelector([]description.ServerSelector{
237+
description.ReadPrefSelector(readpref.Primary()),
238+
description.LatencySelector(db.client.localThreshold),
239+
})
236240
cursor, err := driver.ListCollections(
237241
ctx, cmd,
238242
db.client.topology,
239-
db.readSelector,
243+
readSelector,
240244
db.client.id,
241245
db.client.topology.SessionPool,
242246
opts...,

mongo/index_view.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import (
1616
"github.com/mongodb/mongo-go-driver/bson/bsoncodec"
1717
"github.com/mongodb/mongo-go-driver/bson/bsontype"
1818
"github.com/mongodb/mongo-go-driver/mongo/options"
19+
"github.com/mongodb/mongo-go-driver/mongo/readpref"
1920
"github.com/mongodb/mongo-go-driver/x/bsonx"
2021
"github.com/mongodb/mongo-go-driver/x/mongo/driver"
2122
"github.com/mongodb/mongo-go-driver/x/network/command"
23+
"github.com/mongodb/mongo-go-driver/x/network/description"
2224
)
2325

2426
// ErrInvalidIndexValue indicates that the index Keys document has a value that isn't either a number or a string.
@@ -56,10 +58,14 @@ func (iv IndexView) List(ctx context.Context, opts ...*options.ListIndexesOption
5658
Clock: iv.coll.client.clock,
5759
}
5860

61+
readSelector := description.CompositeSelector([]description.ServerSelector{
62+
description.ReadPrefSelector(readpref.Primary()),
63+
description.LatencySelector(iv.coll.client.localThreshold),
64+
})
5965
return driver.ListIndexes(
6066
ctx, listCmd,
6167
iv.coll.client.topology,
62-
iv.coll.writeSelector,
68+
readSelector,
6369
iv.coll.client.id,
6470
iv.coll.client.topology.SessionPool,
6571
opts...,

0 commit comments

Comments
 (0)