[GODRIVER-1721] (NoSuchTransaction) Transaction 1 has been aborted. Created: 17/Aug/20 Updated: 27/Oct/23 Resolved: 21/Aug/20 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | CRUD |
| Affects Version/s: | 1.3.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | 汇嘉 庄 | Assignee: | Isabella Siu (Inactive) |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Description |
|
My Aim: In a transaction, I want to replace a doc manually instead of aborting the transaction automatically after inserting a doc failed because of `duplicate key error`. The `insert or replace code` shows like below:
The transaction code shows like below:
But it doesn't work.
The log print below:
The Transaction always aborts automatically, cause that I cannot replace the doc manually.
|
| Comments |
| Comment by Isabella Siu (Inactive) [ 21/Aug/20 ] |
|
If any operation in a transaction fails, the server will abort the transaction automatically. https://docs.mongodb.com/manual/core/transactions/#transactions-and-atomicity If upsert doesn't work for your use case, you could start with a FindOne instead of the InsertOne to check if the document already exists instead. |