Skip to content

Commit

Permalink
Update ClaimTask to use options.After for return document
Browse files Browse the repository at this point in the history
  • Loading branch information
yzqzss committed Apr 19, 2024
1 parent 48d32ba commit 2ee9531
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

const DEFAULT_DOC_ID_NAME = "id"
Expand Down Expand Up @@ -58,7 +59,8 @@ func ClaimTask(queue *mongo.Collection, from_status string, archivist string) *p
}}

var task primitive.M
err := queue.FindOneAndUpdate(context.TODO(), filter, update).Decode(&task)
opts := options.FindOneAndUpdate().SetReturnDocument(options.After)
err := queue.FindOneAndUpdate(context.TODO(), filter, update, opts).Decode(&task)
if err != nil {
if err == mongo.ErrNoDocuments {
return nil
Expand Down

0 comments on commit 2ee9531

Please sign in to comment.