Skip to content

Commit d0b4938

Browse files
zhaomeizhaomei
authored andcommitted
fix
1 parent ffd2e49 commit d0b4938

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4895,7 +4895,7 @@ type findModifyCmd struct {
48954895
Collection string `bson:"findAndModify"`
48964896
Query, Update, Sort, Fields interface{} `bson:",omitempty"`
48974897
Upsert, Remove, New bool `bson:",omitempty"`
4898-
WriteConcern interface{} `bson:",omitempty"`
4898+
WriteConcern interface{} `bson:"writeConcern"`
48994899
}
49004900

49014901
type valueResult struct {

session_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ func (s *S) TestFindAndModifyWriteConcern(c *C) {
13761376
defer session.Close()
13771377

13781378
coll := session.DB("mydb").C("mycoll")
1379-
err = coll.Insert(M{"fid": 42})
1379+
err = coll.Insert(M{"id": 42})
13801380
c.Assert(err, IsNil)
13811381

13821382
// Tweak the safety parameters to something unachievable.
@@ -1391,15 +1391,14 @@ func (s *S) TestFindAndModifyWriteConcern(c *C) {
13911391
ReturnNew: false,
13921392
}
13931393
info, err := coll.Find(M{"id": M{"$exists": true}}).Apply(change, &ret)
1394-
c.Assert(err, ErrorMatches, "timeout|timed out waiting for slaves|Not enough data-bearing nodes|waiting for replication timed out")
1395-
if !s.versionAtLeast(2, 6) {
1396-
// 2.6 turned it into a query error.
1397-
c.Assert(err.(*mgo.LastError).WTimeout, Equals, true)
1398-
}
13991394
c.Assert(info.Updated, Equals, 1)
14001395
c.Assert(info.Matched, Equals, 1)
1401-
c.Assert(info.UpsertedId, NotNil)
1402-
c.Assert(ret.Id, Equals, 50)
1396+
c.Assert(ret.Id, Equals, uint64(42))
1397+
1398+
if s.versionAtLeast(3, 2) {
1399+
// findAndModify support writeConcern after version 3.2.
1400+
c.Assert(err, ErrorMatches, "timeout|timed out waiting for slaves|Not enough data-bearing nodes|waiting for replication timed out")
1401+
}
14031402
}
14041403

14051404
func (s *S) TestFindAndModifyBug997828(c *C) {

0 commit comments

Comments
 (0)