@@ -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
265265func (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
0 commit comments