Skip to content

Commit

Permalink
Updated IsIsMasterDoc function to work with drivers that send IsMaste…
Browse files Browse the repository at this point in the history
…r documents with 'isMaster' set to a boolean value instead of a number (#41)
  • Loading branch information
rdeavilafloqast committed Dec 6, 2021
1 parent 7ce5a8a commit 7340694
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions mongo/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,17 @@ func CommandAndCollection(msg bsoncore.Document) (Command, string) {
}

func IsIsMasterDoc(doc bsoncore.Document) bool {
isMaster, _ := doc.Lookup(string(IsMaster)).Int32OK()
ismaster, _ := doc.Lookup(string(Ismaster)).Int32OK()
return ismaster+isMaster > 0
isMaster := doc.Lookup(string(IsMaster))
ismaster := doc.Lookup(string(Ismaster))
return IsIsMasterValueTruthy(isMaster) || IsIsMasterValueTruthy(ismaster)
}

func IsIsMasterValueTruthy(val bsoncore.Value) bool {
if intValue, isInt := val.Int32OK(); intValue > 0 {
return true;
} else if !isInt {
boolValue, isBool := val.BooleanOK()
return boolValue && isBool
}
return false;
}

0 comments on commit 7340694

Please sign in to comment.