Skip to content

Commit cb4da0d

Browse files
committed
Commit missed changes
1 parent efd0ab1 commit cb4da0d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

database/mongodb/mongodb.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (m *Mongo) Open(dsn string) (database.Driver, error) {
157157
if err != nil {
158158
return nil, err
159159
}
160-
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(dsn))
160+
client, err := mongo.Connect(options.Client().ApplyURI(dsn))
161161
if err != nil {
162162
return nil, err
163163
}
@@ -263,16 +263,18 @@ func (m *Mongo) Run(migration io.Reader) error {
263263
}
264264

265265
func (m *Mongo) executeCommandsWithTransaction(ctx context.Context, cmds []bson.D) error {
266-
err := m.db.Client().UseSession(ctx, func(sessionContext mongo.SessionContext) error {
267-
if err := sessionContext.StartTransaction(); err != nil {
266+
err := m.db.Client().UseSession(ctx, func(sessionContext context.Context) error {
267+
sess := mongo.SessionFromContext(ctx)
268+
269+
if err := sess.StartTransaction(); err != nil {
268270
return &database.Error{OrigErr: err, Err: "failed to start transaction"}
269271
}
270272
if err := m.executeCommands(sessionContext, cmds); err != nil {
271273
// When command execution is failed, it's aborting transaction
272274
// If you tried to call abortTransaction, it`s return error that transaction already aborted
273275
return err
274276
}
275-
if err := sessionContext.CommitTransaction(sessionContext); err != nil {
277+
if err := sess.CommitTransaction(sessionContext); err != nil {
276278
return &database.Error{OrigErr: err, Err: "failed to commit transaction"}
277279
}
278280
return nil

database/mongodb/mongodb_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
4848
return false
4949
}
5050

51-
client, err := mongo.Connect(ctx, options.Client().ApplyURI(mongoConnectionString(ip, port)))
51+
client, err := mongo.Connect(options.Client().ApplyURI(mongoConnectionString(ip, port)))
5252
if err != nil {
5353
return false
5454
}

0 commit comments

Comments
 (0)