Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaomei authored and zhaomei committed Jun 7, 2018
1 parent ffd2e49 commit d0b4938
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -4895,7 +4895,7 @@ type findModifyCmd struct {
Collection string `bson:"findAndModify"`
Query, Update, Sort, Fields interface{} `bson:",omitempty"`
Upsert, Remove, New bool `bson:",omitempty"`
WriteConcern interface{} `bson:",omitempty"`
WriteConcern interface{} `bson:"writeConcern"`
}

type valueResult struct {
Expand Down
15 changes: 7 additions & 8 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ func (s *S) TestFindAndModifyWriteConcern(c *C) {
defer session.Close()

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

// Tweak the safety parameters to something unachievable.
Expand All @@ -1391,15 +1391,14 @@ func (s *S) TestFindAndModifyWriteConcern(c *C) {
ReturnNew: false,
}
info, err := coll.Find(M{"id": M{"$exists": true}}).Apply(change, &ret)
c.Assert(err, ErrorMatches, "timeout|timed out waiting for slaves|Not enough data-bearing nodes|waiting for replication timed out")
if !s.versionAtLeast(2, 6) {
// 2.6 turned it into a query error.
c.Assert(err.(*mgo.LastError).WTimeout, Equals, true)
}
c.Assert(info.Updated, Equals, 1)
c.Assert(info.Matched, Equals, 1)
c.Assert(info.UpsertedId, NotNil)
c.Assert(ret.Id, Equals, 50)
c.Assert(ret.Id, Equals, uint64(42))

if s.versionAtLeast(3, 2) {
// findAndModify support writeConcern after version 3.2.
c.Assert(err, ErrorMatches, "timeout|timed out waiting for slaves|Not enough data-bearing nodes|waiting for replication timed out")
}
}

func (s *S) TestFindAndModifyBug997828(c *C) {
Expand Down

0 comments on commit d0b4938

Please sign in to comment.