We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sess, err := m.conn.StartSession() if err != nil { return err } defer sess.EndSession(ctx) err = sess.StartTransaction() if err != nil { return err } ctx = mongo.NewSessionContext(ctx, sess) defer func() { if err != nil { _ = sess.AbortTransaction(ctx) } }() for _, item := range data { _, err = m.conn.Collection.InsertOne(ctx, item) if err != nil { return err } } _ = sess.CommitTransaction(ctx) return nil
but as follows,it's useful !!!!!!!!!!!!!!!
sess, err := m.conn.StartSession() if err != nil { return err } defer sess.EndSession(ctx) _, err = sess.WithTransaction(ctx, func(sessCtx mongo.SessionContext) (interface{}, error) { defer func() { if err != nil { _ = sessCtx.AbortTransaction(ctx) } }() for _, item := range data { _, err = m.conn.Collection.InsertOne(sessCtx, item) if err != nil { return nil, err } } err = sessCtx.CommitTransaction(sessCtx) return nil, err }) if err != nil { return err }
The text was updated successfully, but these errors were encountered:
Didn't get what's the problem?
Sorry, something went wrong.
No branches or pull requests
but as follows,it's useful !!!!!!!!!!!!!!!
The text was updated successfully, but these errors were encountered: