globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 230 forks source link

mgo still not support writeConcern for findAndModify #176

Closed Mei-Zhao closed 6 years ago

Mei-Zhao commented 6 years ago

mongod has support writeConcern for findAndModify command since v3.2

https://docs.mongodb.com/v3.4/reference/command/findAndModify/#dbcmd.findAndModify(the Output part still not update)

If the cluster has been set with getLastErrorDefaults like:

` "getLastErrorDefaults" : {

  "w" : "majority",

  "wtimeout" : 5000

} `

The cluster has 5 nodes and 3 of them have been locked by fsyncLock(). The test result returned from Mongod (v3.4) about a findAndModify command like

findAndModify: { "lastErrorObject" : { "n" : 1, "updatedExisting" : true }, "ok" : 1, "writeConcernError" : { "code" : 64, "errInfo" : { "wtimeout" : true }, "errmsg" : "waiting for replication timed out", "codeName" : "WriteConcernFailed" }, "value" : { "fid" : 367585860, "_id" : "5afbf542588399814fe36b5a" } }

The findAndModify result define in mgo seesion.go did not deal with writeConcernErr,in detail:

` type valueResult struct {

Value     bson.Raw

LastError LastError `bson:"lastErrorObject"`

}`

domodwyer commented 6 years ago

Hi @Mei-Zhao

This mgo fork is a community project - we'll happily accept a PR for findAndModify!

Dom