refactor: Update models to use DatabaseV2 instead of DataSourceV2

This commit is contained in:
Marvin Zhang
2024-08-05 16:07:19 +08:00
parent e57655c67e
commit 421a06930c
3 changed files with 50 additions and 46 deletions

View File

@@ -111,28 +111,13 @@ func getMongoClientV2(ctx context.Context, ds *models2.DatabaseV2) (c *mongo2.Cl
// options
var opts []mongo.ClientOption
opts = append(opts, mongo.WithContext(ctx))
opts = append(opts, mongo.WithUri(ds.Url))
opts = append(opts, mongo.WithUri(ds.URI))
opts = append(opts, mongo.WithHost(ds.Host))
opts = append(opts, mongo.WithPort(ds.Port))
opts = append(opts, mongo.WithDb(ds.Database))
opts = append(opts, mongo.WithUsername(ds.Username))
opts = append(opts, mongo.WithPassword(ds.Password))
// extra
if ds.Extra != nil {
// auth source
authSource, ok := ds.Extra["auth_source"]
if ok {
opts = append(opts, mongo.WithAuthSource(authSource))
}
// auth mechanism
authMechanism, ok := ds.Extra["auth_mechanism"]
if ok {
opts = append(opts, mongo.WithAuthMechanism(authMechanism))
}
}
// client
return mongo.GetMongoClient(opts...)
}