diff --git a/mongodb/config.go b/mongodb/config.go index d52cd499..bcc1fed8 100644 --- a/mongodb/config.go +++ b/mongodb/config.go @@ -2,6 +2,11 @@ package mongodb // Config defines the config for storage. type Config struct { + // Whether the DB is hosted on MongoDB Atlas + // + // Optional. Default is false + Atlas bool + // Host name where the DB is hosted // // Optional. Default is "127.0.0.1" @@ -40,6 +45,7 @@ type Config struct { // ConfigDefault is the default config var ConfigDefault = Config{ + Atlas: false, Host: "127.0.0.1", Port: 27017, Database: "fiber", diff --git a/mongodb/mongodb.go b/mongodb/mongodb.go index ccc07258..7520eae5 100644 --- a/mongodb/mongodb.go +++ b/mongodb/mongodb.go @@ -33,7 +33,12 @@ func New(config ...Config) *Storage { cfg := configDefault(config...) // Create data source name - var dsn = "mongodb://" + var dsn = "mongodb" + if cfg.Atlas == true { + dsn += "+srv://" + } else { + dsn += "://" + } if cfg.Username != "" { dsn += url.QueryEscape(cfg.Username) }