mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
Updated mongo ensureIndexes
This commit is contained in:
committed by
Dan Christian Bogos
parent
de41b7a093
commit
965f645d09
@@ -259,8 +259,16 @@ func (ms *MongoStorage) GetContext() context.Context {
|
||||
return ms.ctx
|
||||
}
|
||||
|
||||
func isNotFound(err error) bool {
|
||||
de, ok := err.(mongo.CommandError)
|
||||
if !ok { // if still can't converted to the mongo.CommandError check if error do not contains message
|
||||
return strings.Contains(err.Error(), "ns not found")
|
||||
}
|
||||
return de.Code == 26 || de.Message == "ns not found"
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) ensureIndexesForCol(col string) (err error) { // exported for migrator
|
||||
if err = ms.dropAllIndexesForCol(col); err != nil && err.Error() != "ns not found" { // make sure you do not have indexes
|
||||
if err = ms.dropAllIndexesForCol(col); err != nil && !isNotFound(err) { // make sure you do not have indexes
|
||||
return
|
||||
}
|
||||
err = nil
|
||||
|
||||
Reference in New Issue
Block a user