fix: ignore error on indexes already exist
This commit is contained in:
parent
073555ba04
commit
bc137e9317
1 changed files with 7 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ package database
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
|
@ -55,7 +56,12 @@ func NewMongoDB(ctx context.Context, connectionURI, databaseName, collectionName
|
|||
|
||||
_, err = collection.Indexes().CreateMany(ctx, models)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// Mongo will error if the index already exists, we can ignore this and continue.
|
||||
if err.(mongo.CommandError).Code != 86 {
|
||||
return nil, err
|
||||
} else {
|
||||
log.Printf("Indexes already exists, skipping.")
|
||||
}
|
||||
}
|
||||
|
||||
return &MongoDB{
|
||||
|
|
|
|||
Loading…
Reference in a new issue