Files
crawlab/core/mongo/db.go
Marvin Zhang dc59599509 refactor: remove db module and update imports to core/mongo
- Deleted the db module, consolidating database-related functionality into the core/mongo package for better organization and maintainability.
- Updated all import paths across the codebase to replace references to the removed db module with core/mongo.
- Cleaned up unused code and dependencies, enhancing overall project clarity and reducing complexity.
- This refactor improves the structure of the codebase by centralizing database operations and simplifying module management.
2024-12-25 10:28:21 +08:00

24 lines
435 B
Go

package mongo
import (
"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 {
logger.Errorf("error getting mongo client: %v", err)
return nil
}
return c.Database(dbName)
}