mirror of
https://github.com/gofiber/storage.git
synced 2025-10-06 00:57:38 +08:00
Add index for key field
This commit is contained in:
@@ -100,6 +100,19 @@ func New(config ...Config) *Storage {
|
|||||||
panic(err)
|
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{
|
store := &Storage{
|
||||||
db: db,
|
db: db,
|
||||||
col: col,
|
col: col,
|
||||||
|
Reference in New Issue
Block a user