|
|
@ -5,18 +5,14 @@ import ( |
|
|
|
"fmt" |
|
|
|
"go.mongodb.org/mongo-driver/mongo" |
|
|
|
"go.mongodb.org/mongo-driver/mongo/options" |
|
|
|
"sync" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
var ( |
|
|
|
collection *mongo.Collection |
|
|
|
mLock sync.Mutex |
|
|
|
) |
|
|
|
|
|
|
|
func NewMongoDriver(config db, level int) (driver, error) { |
|
|
|
mLock.Lock() |
|
|
|
defer mLock.Unlock() |
|
|
|
if collection == nil { |
|
|
|
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) |
|
|
|
client, err := mongo.Connect(ctx, options.Client().ApplyURI(fmt.Sprintf("mongodb://%s:%d", config.Host, config.Port))) |
|
|
|