package mongo import ( "context" "fmt" "github.com/qiniu/qmgo" "go.mongodb.org/mongo-driver/mongo/readpref" goproto "google.golang.org/protobuf/proto" ) func NewMongoClient() (*qmgo.Client, error) { clientCfg := &qmgo.Config{ Uri: "mongodb://root:Wishpal2024@dds-bp1628b447c242e41.mongodb.rds.aliyuncs.com:3717,dds-bp1628b447c242e42.mongodb.rds.aliyuncs.com:3717/admin?replicaSet=mgset-74245203", ConnectTimeoutMS: goproto.Int64(30000), MaxPoolSize: goproto.Uint64(16), MinPoolSize: goproto.Uint64(0), SocketTimeoutMS: goproto.Int64(5000), ReadPreference: &qmgo.ReadPref{Mode: readpref.PrimaryMode}, } cli, err := qmgo.NewClient(context.Background(), clientCfg) if err != nil { fmt.Printf("NewMongoClient fail, cfg: %v, err: %v", clientCfg, err) return nil, err } return cli, nil }