mirror of
https://github.com/duanhf2012/origin.git
synced 2026-03-14 21:03:33 +08:00
优化mongodbmodule的NextSeq接口
This commit is contained in:
@@ -65,7 +65,10 @@ func (s *Session) NextSeq(db string, collection string, id interface{}) (int, er
|
|||||||
|
|
||||||
ctxTimeout, cancel := s.GetDefaultContext()
|
ctxTimeout, cancel := s.GetDefaultContext()
|
||||||
defer cancel()
|
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
|
return res.Seq, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user