centrelized collection creation logic

This commit is contained in:
2025-03-19 13:27:43 +02:00
parent 946bd6018f
commit ba47810398
4 changed files with 39 additions and 39 deletions

View File

@@ -196,21 +196,12 @@ func (self *ServersDbHandler) GetInviteToken(ctx context.Context, token string)
}
func NewInviteTokenDbHandler(config models.MongoDBConfig) (*InviteTokenDbHandler, error) {
clientOptions := options.Client().ApplyURI(config.Url).SetAuth(options.Credential{
Username: config.Username,
Password: config.Password,
})
ctx, cancel := context.WithTimeoutCause(context.Background(), 30*time.Second, fmt.Errorf("Timeout"))
defer cancel()
client, err := mongo.Connect(ctx, clientOptions)
collection, err := getMongoCollection(config)
if err != nil {
return nil, err
}
return &InviteTokenDbHandler{
collection: client.Database(config.Database).Collection(config.Collection),
collection: collection,
}, nil
}