mirror of
https://github.com/gofiber/storage.git
synced 2025-10-05 08:37:10 +08:00
Merge remote-tracking branch 'upstream/main' into main
This commit is contained in:
@@ -48,7 +48,6 @@ store := mongodb.New(mongodb.Config{
|
||||
Database: "fiber",
|
||||
Collection: "fiber_storage",
|
||||
Reset: false,
|
||||
GCInterval: 10 * time.Second,
|
||||
})
|
||||
```
|
||||
|
||||
@@ -89,11 +88,6 @@ type Config struct {
|
||||
//
|
||||
// Optional. Default is false
|
||||
Reset bool
|
||||
|
||||
// Time before deleting expired keys
|
||||
//
|
||||
// Optional. Default is 10 * time.Second
|
||||
GCInterval time.Duration
|
||||
}
|
||||
```
|
||||
|
||||
@@ -105,6 +99,5 @@ var ConfigDefault = Config{
|
||||
Database: "fiber",
|
||||
Collection: "fiber_storage",
|
||||
Reset: false,
|
||||
GCInterval: 10 * time.Second,
|
||||
}
|
||||
```
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package mongodb
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
import "time"
|
||||
|
||||
// Config defines the config for storage.
|
||||
type Config struct {
|
||||
@@ -54,7 +52,6 @@ var ConfigDefault = Config{
|
||||
Database: "fiber",
|
||||
Collection: "fiber_storage",
|
||||
Reset: false,
|
||||
GCInterval: 10 * time.Second,
|
||||
}
|
||||
|
||||
// Helper function to set default values
|
||||
|
@@ -37,7 +37,7 @@ func New(config ...Config) *Storage {
|
||||
cfg := configDefault(config...)
|
||||
|
||||
// Create data source name
|
||||
var dsn string = "mongodb://"
|
||||
var dsn = "mongodb://"
|
||||
if cfg.Username != "" {
|
||||
dsn += url.QueryEscape(cfg.Username)
|
||||
}
|
||||
@@ -65,10 +65,21 @@ func New(config ...Config) *Storage {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// verify that the client can connect
|
||||
if err = client.Ping(context.Background(), nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Get collection from database
|
||||
db := client.Database(cfg.Database)
|
||||
col := db.Collection(cfg.Collection)
|
||||
|
||||
if cfg.Clear {
|
||||
if err = col.Drop(context.Background()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// expired data may exist for some time beyond the 60 second period between runs of the background task.
|
||||
// more on https://docs.mongodb.com/manual/core/index-ttl/
|
||||
indexModel := mongo.IndexModel{
|
||||
|
Reference in New Issue
Block a user