add monitor options #5
			
				
			
		
		
		
	| 
						 | 
					@ -5,6 +5,7 @@ import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/logrusorgru/aurora"
 | 
						"github.com/logrusorgru/aurora"
 | 
				
			||||||
 | 
						"go.mongodb.org/mongo-driver/event"
 | 
				
			||||||
	"go.mongodb.org/mongo-driver/mongo"
 | 
						"go.mongodb.org/mongo-driver/mongo"
 | 
				
			||||||
	"go.mongodb.org/mongo-driver/mongo/options"
 | 
						"go.mongodb.org/mongo-driver/mongo/options"
 | 
				
			||||||
	"go.mongodb.org/mongo-driver/mongo/readpref"
 | 
						"go.mongodb.org/mongo-driver/mongo/readpref"
 | 
				
			||||||
| 
						 | 
					@ -14,6 +15,7 @@ import (
 | 
				
			||||||
type Config struct {
 | 
					type Config struct {
 | 
				
			||||||
	Host    string
 | 
						Host    string
 | 
				
			||||||
	DBName  string
 | 
						DBName  string
 | 
				
			||||||
 | 
						Monitor *event.CommandMonitor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	TLS        *ConnectTLSOpts
 | 
						TLS        *ConnectTLSOpts
 | 
				
			||||||
	Standalone *ConnectStandaloneOpts
 | 
						Standalone *ConnectStandaloneOpts
 | 
				
			||||||
| 
						 | 
					@ -86,6 +88,9 @@ func connectWithTLS(cfg Config) (*mongo.Database, error) {
 | 
				
			||||||
	uri := fmt.Sprintf(s, cfg.Host, caFile.Name(), certFile.Name(), pwd)
 | 
						uri := fmt.Sprintf(s, cfg.Host, caFile.Name(), certFile.Name(), pwd)
 | 
				
			||||||
	readPref := getReadPref(opts.ReadPreferenceMode)
 | 
						readPref := getReadPref(opts.ReadPreferenceMode)
 | 
				
			||||||
	clientOpts := options.Client().SetReadPreference(readPref).SetReplicaSet(opts.ReplSet).ApplyURI(uri)
 | 
						clientOpts := options.Client().SetReadPreference(readPref).SetReplicaSet(opts.ReplSet).ApplyURI(uri)
 | 
				
			||||||
 | 
						if cfg.Monitor != nil {
 | 
				
			||||||
 | 
							clientOpts.SetMonitor(cfg.Monitor)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	client, err := mongo.Connect(ctx, clientOpts)
 | 
						client, err := mongo.Connect(ctx, clientOpts)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue