Skip to content

Commit

Permalink
fix(mongox): transaction read pref should be primary (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyshx authored Jul 29, 2024
1 parent 3b7cfe4 commit 4287cd4
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions mongox/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/reearth/reearthx/usecasex"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
"go.mongodb.org/mongo-driver/x/mongo/driver"
)

Expand All @@ -24,13 +23,7 @@ func NewTransaction(client *mongo.Client) *Transaction {
}

func (t *Transaction) Begin(ctx context.Context) (usecasex.Tx, error) {
// Set the read preference to Nearest
rp := readpref.Nearest()

// Create session options with the Nearest read preference
sessionOpts := options.Session().SetDefaultReadPreference(rp)

s, err := t.client.StartSession(sessionOpts)
s, err := t.client.StartSession(options.Session())
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 4287cd4

Please sign in to comment.