From f966e173d7b53c469b1b2871ce88c40d79c833de Mon Sep 17 00:00:00 2001 From: "Sokolov Yura aka funny.falcon" Date: Fri, 12 Jul 2019 22:20:43 +0300 Subject: [PATCH 1/2] fix serialization of readConcern Private field `level` were not serialized to BSON, therefore it were never sent to mongos/mongod. Make it public. --- session.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/session.go b/session.go index cd2a53e19..2b0f7a65a 100644 --- a/session.go +++ b/session.go @@ -2912,7 +2912,6 @@ func (p *Pipe) SetMaxTime(d time.Duration) *Pipe { return p } - // Collation allows to specify language-specific rules for string comparison, // such as rules for lettercase and accent marks. // When specifying collation, the locale field is mandatory; all other collation @@ -3769,7 +3768,7 @@ func prepareFindOp(socket *mongoSocket, op *queryOp, limit int32) bool { AwaitData: op.flags&flagAwaitData != 0, OplogReplay: op.flags&flagLogReplay != 0, NoCursorTimeout: op.flags&flagNoCursorTimeout != 0, - ReadConcern: readLevel{level: op.readConcern}, + ReadConcern: readLevel{Level: op.readConcern}, } if op.limit < 0 { @@ -3838,7 +3837,7 @@ type findCmd struct { // readLevel provides the nested "level: majority" serialisation needed for the // query read concern. type readLevel struct { - level string `bson:"level,omitempty"` + Level string `bson:"level,omitempty"` } // getMoreCmd holds the command used for requesting more query results on MongoDB 3.2+. From ae83d590827be60a3cdb6dafac2991de960d74ab Mon Sep 17 00:00:00 2001 From: "Sokolov Yura aka funny.falcon" Date: Fri, 12 Jul 2019 23:59:24 +0300 Subject: [PATCH 2/2] unset read concern in explain explain command doesn't support read concern. It is convenient to call explain before query itself in tests. Lets reset readConcern for convenience therefore user doesn't have to do it by hand. --- session.go | 1 + 1 file changed, 1 insertion(+) diff --git a/session.go b/session.go index 2b0f7a65a..ac8c1cf4e 100644 --- a/session.go +++ b/session.go @@ -3788,6 +3788,7 @@ func prepareFindOp(socket *mongoSocket, op *queryOp, limit int32) bool { op.hasOptions = false if explain { + find.ReadConcern.Level = "" op.query = bson.D{{Name: "explain", Value: op.query}} return false }