mirror of
https://github.com/gofiber/storage.git
synced 2025-10-05 16:48:25 +08:00
Add index for key field
This commit is contained in:
@@ -100,6 +100,19 @@ func New(config ...Config) *Storage {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Create unique index for the "key" field
|
||||
keyIndexModel := mongo.IndexModel{
|
||||
Keys: bson.D{{
|
||||
Key: "key",
|
||||
Value: 1,
|
||||
}},
|
||||
Options: options.Index().SetUnique(true),
|
||||
}
|
||||
|
||||
if _, err := col.Indexes().CreateOne(ctx, keyIndexModel); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
store := &Storage{
|
||||
db: db,
|
||||
col: col,
|
||||
|
Reference in New Issue
Block a user