mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
25 lines
455 B
Go
25 lines
455 B
Go
package mongo
|
|
|
|
import (
|
|
"github.com/apex/log"
|
|
"github.com/spf13/viper"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
func GetMongoDb(dbName string) *mongo.Database {
|
|
// Use default database name if not provided
|
|
if dbName == "" {
|
|
if dbName = viper.GetString("mongo.db"); dbName == "" {
|
|
dbName = "test"
|
|
}
|
|
}
|
|
|
|
c, err := GetMongoClient()
|
|
if err != nil {
|
|
log.Errorf("error getting mongo client: %v", err)
|
|
return nil
|
|
}
|
|
|
|
return c.Database(dbName)
|
|
}
|