We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e120097 commit aca8f84Copy full SHA for aca8f84
mongox/client.go
@@ -6,6 +6,8 @@ import (
6
7
"github.com/reearth/reearthx/usecasex"
8
"go.mongodb.org/mongo-driver/mongo"
9
+ "go.mongodb.org/mongo-driver/mongo/options"
10
+ "go.mongodb.org/mongo-driver/mongo/readpref"
11
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
12
)
13
@@ -15,8 +17,12 @@ type Client struct {
15
17
}
16
18
19
func NewClient(database string, c *mongo.Client) *Client {
20
+ rp := readpref.Nearest()
21
+
22
+ sessionOpts := options.Database().SetReadPreference(rp)
23
24
return &Client{
- db: c.Database(database),
25
+ db: c.Database(database, sessionOpts),
26
transaction: &usecasex.NopTransaction{},
27
28
0 commit comments