Skip to content

Commit

Permalink
Merge pull request #82 from pinguo-yangbing/master
Browse files Browse the repository at this point in the history
mongo session mode
  • Loading branch information
pinguo-yangbing authored Sep 28, 2020
2 parents fd00f34 + 53bf5a1 commit c69e5a4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion client/mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
// connectTimeout: "1s"
// readTimeout: "10s"
// writeTimeout: "10s"
// mode: 1/2
//
// see Dial() for query options, default:
// replicaSet=
Expand All @@ -29,6 +30,7 @@ import (
// j=false
// wtimeoutMS=10000
// readPreference=secondaryPreferred

func New(config map[string]interface{}) (interface{}, error) {
c := &Client{}
c.dsn = defaultDsn
Expand All @@ -53,6 +55,7 @@ type Client struct {
connectTimeout time.Duration
readTimeout time.Duration
writeTimeout time.Duration
mode int
}

func (c *Client) Init() error {
Expand Down Expand Up @@ -84,11 +87,20 @@ func (c *Client) Init() error {
return fmt.Errorf(errDialFailed, c.dsn, e.Error())
}

c.session.SetMode(mgo.Monotonic, true)
//c.session.SetMode(mgo.Monotonic, true)
if c.mode == 0 {
c.mode = 1
}

c.session.SetMode(mgo.Mode(c.mode), true)

return nil
}

func (c *Client) SetMode(mode int) {
c.mode = mode
}

func (c *Client) SetDsn(dsn string) {
c.dsn = dsn
}
Expand Down

0 comments on commit c69e5a4

Please sign in to comment.