优化mongodbmodule的NextSeq接口

This commit is contained in:
orgin
2022-04-01 17:35:13 +08:00
parent 4d5d45d555
commit 63199bf862

View File

@@ -65,7 +65,10 @@ func (s *Session) NextSeq(db string, collection string, id interface{}) (int, er
ctxTimeout, cancel := s.GetDefaultContext()
defer cancel()
err := s.Client.Database(db).Collection(collection).FindOneAndUpdate(ctxTimeout, bson.M{"_id": id}, bson.M{"$inc": bson.M{"Seq": 1}}).Decode(&res)
after := options.After
updateOpts := options.FindOneAndUpdateOptions{ReturnDocument: &after}
err := s.Client.Database(db).Collection(collection).FindOneAndUpdate(ctxTimeout, bson.M{"_id": id}, bson.M{"$inc": bson.M{"Seq": 1}},&updateOpts).Decode(&res)
return res.Seq, err
}