File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 7
7
"github.com/reearth/reearthx/usecasex"
8
8
"go.mongodb.org/mongo-driver/mongo"
9
9
"go.mongodb.org/mongo-driver/mongo/options"
10
+ "go.mongodb.org/mongo-driver/mongo/readpref"
10
11
"go.mongodb.org/mongo-driver/x/mongo/driver"
11
12
)
12
13
@@ -23,7 +24,13 @@ func NewTransaction(client *mongo.Client) *Transaction {
23
24
}
24
25
25
26
func (t * Transaction ) Begin (ctx context.Context ) (usecasex.Tx , error ) {
26
- s , err := t .client .StartSession (options .Session ())
27
+ // Set the read preference to Nearest
28
+ rp := readpref .Nearest ()
29
+
30
+ // Create session options with the Nearest read preference
31
+ sessionOpts := options .Session ().SetDefaultReadPreference (rp )
32
+
33
+ s , err := t .client .StartSession (sessionOpts )
27
34
if err != nil {
28
35
return nil , err
29
36
}
You can’t perform that action at this time.
0 commit comments