Skip to content

Commit

Permalink
feat: use buildInfo for ServerVersion func, DoTransaction still check…
Browse files Browse the repository at this point in the history
… transactionAllowed
  • Loading branch information
zhb127 committed May 6, 2021
1 parent 2310448 commit 6f2e68f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ func (c *Client) Session() (*Session, error) {
// - if operations in callback return qmgo.ErrTransactionNotSupported,
// - If the ctx parameter already has a Session attached to it, it will be replaced by this session.
func (c *Client) DoTransaction(ctx context.Context, callback func(sessCtx context.Context) (interface{}, error)) (interface{}, error) {
if !c.transactionAllowed() {
return nil, ErrTransactionNotSupported
}
s, err := c.Session()
if err != nil {
return nil, err
Expand All @@ -323,16 +326,16 @@ func (c *Client) DoTransaction(ctx context.Context, callback func(sessCtx contex

// ServerVersion get the version of mongoDB server, like 4.4.0
func (c *Client) ServerVersion() string {
var serverStatus bson.Raw
var buildInfo bson.Raw
err := c.client.Database("admin").RunCommand(
context.Background(),
bson.D{{"serverStatus", 1}},
).Decode(&serverStatus)
bson.D{{"buildInfo", 1}},
).Decode(&buildInfo)
if err != nil {
fmt.Println("run command err", err)
return ""
}
v, err := serverStatus.LookupErr("version")
v, err := buildInfo.LookupErr("version")
if err != nil {
fmt.Println("look up err", err)
return ""
Expand Down

0 comments on commit 6f2e68f

Please sign in to comment.