diff --git a/engine/storage_interface.go b/engine/storage_interface.go index d2428777c..4c5928dfc 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -27,7 +27,7 @@ import ( "github.com/cgrates/cgrates/utils" "github.com/ugorji/go/codec" - "go.mongodb.org/mongo-driver/bson" + "github.com/mongodb/mongo-go-driver/bson" ) type Storage interface { diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 9fe259dd8..7ef74257c 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -33,14 +33,15 @@ import ( "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/bson/bsoncodec" - "go.mongodb.org/mongo-driver/bson/bsonrw" - "go.mongodb.org/mongo-driver/bson/bsontype" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" - "go.mongodb.org/mongo-driver/x/bsonx" + "github.com/mongodb/mongo-go-driver/bson" + "github.com/mongodb/mongo-go-driver/bson/bsoncodec" + "github.com/mongodb/mongo-go-driver/bson/bsonrw" + "github.com/mongodb/mongo-go-driver/bson/bsontype" + "github.com/mongodb/mongo-go-driver/bson/primitive" + "github.com/mongodb/mongo-go-driver/mongo" + "github.com/mongodb/mongo-go-driver/mongo/options" + "github.com/mongodb/mongo-go-driver/x/bsonx" + "github.com/mongodb/mongo-go-driver/x/network/command" ) const ( @@ -146,11 +147,10 @@ func NewMongoStorage(host, port, db, user, pass, storageType string, cdrsIndexes url = "mongodb://" + url reg := bson.NewRegistryBuilder().RegisterDecoder(tTime, bsoncodec.ValueDecoderFunc(TimeDecodeValue1)).Build() opt := options.Client(). - ApplyURI(url). SetRegistry(reg). SetServerSelectionTimeout(ttl) - client, err := mongo.NewClient(opt) + client, err := mongo.NewClientWithOptions(url, opt) // client, err := mongo.NewClient(url) if err != nil { @@ -259,16 +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 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 && !isNotFound(err) { // make sure you do not have indexes + if err = ms.dropAllIndexesForCol(col); err != nil && !command.IsNotFound(err) { // make sure you do not have indexes return } err = nil diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index 207d60b69..d652c40a4 100644 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -27,10 +27,10 @@ import ( "github.com/cgrates/cgrates/utils" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" - "go.mongodb.org/mongo-driver/x/bsonx" + "github.com/mongodb/mongo-go-driver/bson" + "github.com/mongodb/mongo-go-driver/mongo" + "github.com/mongodb/mongo-go-driver/mongo/options" + "github.com/mongodb/mongo-go-driver/x/bsonx" ) func (ms *MongoStorage) GetTpIds(colName string) (tpids []string, err error) { @@ -1572,10 +1572,13 @@ func (ms *MongoStorage) RemoveVersions(vrs Versions) (err error) { if len(vrs) == 0 { return ms.query(func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(ColVer).DeleteOne(sctx, bson.D{}) + if err != nil { + return err + } if dr.DeletedCount == 0 { return utils.ErrNotFound } - return err + return nil }) } return ms.query(func(sctx mongo.SessionContext) (err error) { diff --git a/glide.lock b/glide.lock index 59151e32a..8984f7f93 100644 --- a/glide.lock +++ b/glide.lock @@ -151,37 +151,25 @@ imports: version: 7eeb5667e42c09cb51bf7b7c28aea8c56767da90 - name: github.com/xdg/stringprep version: 73f8eece6fdcd902c185bf651de50f3828bed5ed -- name: go.mongodb.org/mongo-driver - version: 9ec4480161a76f5267d56fc836b7f6d357fd9209 +- name: github.com/mongodb/mongo-go-driver + version: 4f3b0a882e7d5f83c3d1ab4d0e530a51642fce03 subpackages: - bson - bson/bsoncodec - bson/bsonrw - bson/bsontype - bson/primitive - - event - internal - mongo - - mongo/options - mongo/readconcern - mongo/readpref - mongo/writeconcern - - tag - - version - x/bsonx - x/bsonx/bsoncore - - x/mongo/driver - - x/mongo/driver/address - - x/mongo/driver/auth - - x/mongo/driver/auth/internal/gssapi - - x/mongo/driver/connstring - - x/mongo/driver/description - - x/mongo/driver/dns - - x/mongo/driver/operation - - x/mongo/driver/session - x/mongo/driver/topology - x/mongo/driver/uuid - x/mongo/driver/wiremessage + - mongo/options - name: go.opencensus.io version: b4a14686f0a98096416fe1b4cb848e384fb2b22b subpackages: diff --git a/glide.yaml b/glide.yaml index 4b60ea54d..b921b5ac4 100644 --- a/glide.yaml +++ b/glide.yaml @@ -38,7 +38,7 @@ import: - package: github.com/cgrates/radigo - package: github.com/cgrates/ltcache - package: github.com/antchfx/xmlquery -- package: go.mongodb.org/mongo-driver +- package: github.com/mongodb/mongo-go-driver subpackages: - bson - bson/bsoncodec diff --git a/migrator/storage_mongo_datadb.go b/migrator/storage_mongo_datadb.go index 0e92dc220..4b4b98b2f 100644 --- a/migrator/storage_mongo_datadb.go +++ b/migrator/storage_mongo_datadb.go @@ -21,9 +21,9 @@ package migrator import ( "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "github.com/mongodb/mongo-go-driver/bson" + "github.com/mongodb/mongo-go-driver/mongo" + "github.com/mongodb/mongo-go-driver/mongo/options" ) const ( @@ -72,10 +72,12 @@ func (mgoMig *mongoMigrator) DataManager() *engine.DataManager { //get func (v1ms *mongoMigrator) getv1Account() (v1Acnt *v1Account, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(v1AccountDBPrefix).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(v1AccountDBPrefix).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -107,10 +109,12 @@ func (v1ms *mongoMigrator) remV1Account(id string) (err error) { //get func (v1ms *mongoMigrator) getv2Account() (v2Acnt *v2Account, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(v2AccountsCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(v2AccountsCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -143,10 +147,12 @@ func (v1ms *mongoMigrator) remV2Account(id string) (err error) { func (v1ms *mongoMigrator) getV1ActionPlans() (v1aps *v1ActionPlans, err error) { strct := new(AtKeyValue) if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection("actiontimings").Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection("actiontimings").Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -171,10 +177,12 @@ func (v1ms *mongoMigrator) setV1ActionPlans(x *v1ActionPlans) (err error) { func (v1ms *mongoMigrator) getV1Actions() (v1acs *v1Actions, err error) { strct := new(AcKeyValue) if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection("actions").Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection("actions").Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -198,10 +206,12 @@ func (v1ms *mongoMigrator) setV1Actions(x *v1Actions) (err error) { //get func (v1ms *mongoMigrator) getV1ActionTriggers() (v1acts *v1ActionTriggers, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(v1ActionTriggersCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(v1ActionTriggersCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -230,10 +240,12 @@ func (v1ms *mongoMigrator) setV1ActionTriggers(act *v1ActionTriggers) (err error //get func (v1ms *mongoMigrator) getV1SharedGroup() (v1sg *v1SharedGroup, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(utils.SHARED_GROUP_PREFIX).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(utils.SHARED_GROUP_PREFIX).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -257,10 +269,12 @@ func (v1ms *mongoMigrator) setV1SharedGroup(x *v1SharedGroup) (err error) { //get func (v1ms *mongoMigrator) getV1Stats() (v1st *v1Stat, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(utils.CDR_STATS_PREFIX).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(utils.CDR_STATS_PREFIX).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -284,10 +298,12 @@ func (v1ms *mongoMigrator) setV1Stats(x *v1Stat) (err error) { //get func (v1ms *mongoMigrator) getV2ActionTrigger() (v2at *v2ActionTrigger, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(v1ActionTriggersCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(v1ActionTriggersCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -311,10 +327,12 @@ func (v1ms *mongoMigrator) setV2ActionTrigger(x *v2ActionTrigger) (err error) { //get func (v1ms *mongoMigrator) getV1AttributeProfile() (v1attrPrf *v1AttributeProfile, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(v1AttributeProfilesCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(v1AttributeProfilesCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -338,10 +356,12 @@ func (v1ms *mongoMigrator) setV1AttributeProfile(x *v1AttributeProfile) (err err //get func (v1ms *mongoMigrator) getV2ThresholdProfile() (v2T *v2Threshold, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(v2ThresholdProfileCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(v2ThresholdProfileCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -371,10 +391,12 @@ func (v1ms *mongoMigrator) remV2ThresholdProfile(tenant, id string) (err error) //get func (v1ms *mongoMigrator) getV1Alias() (v1a *v1Alias, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(v1AliasCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(v1AliasCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -449,10 +471,12 @@ func (v1ms *mongoMigrator) remV1Alias(key string) (err error) { //get func (v1ms *mongoMigrator) getV1User() (v1u *v1UserProfile, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(v1UserCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(v1UserCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -491,10 +515,12 @@ func (v1ms *mongoMigrator) remV1User(key string) (err error) { //get func (v1ms *mongoMigrator) getV1DerivedChargers() (v1d *v1DerivedChargersWithKey, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(v1DerivedChargersCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(v1DerivedChargersCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -527,10 +553,12 @@ func (v1ms *mongoMigrator) remV1DerivedChargers(key string) (err error) { //get func (v1ms *mongoMigrator) getV2AttributeProfile() (v2attrPrf *v2AttributeProfile, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(v1AttributeProfilesCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(v1AttributeProfilesCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -560,10 +588,12 @@ func (v1ms *mongoMigrator) remV2AttributeProfile(tenant, id string) (err error) //get func (v1ms *mongoMigrator) getV3AttributeProfile() (v3attrPrf *v3AttributeProfile, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(v1AttributeProfilesCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(v1AttributeProfilesCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) diff --git a/migrator/storage_mongo_stordb.go b/migrator/storage_mongo_stordb.go index 6421ecf9f..e02c748c2 100644 --- a/migrator/storage_mongo_stordb.go +++ b/migrator/storage_mongo_stordb.go @@ -21,8 +21,8 @@ package migrator import ( "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" + "github.com/mongodb/mongo-go-driver/bson" + "github.com/mongodb/mongo-go-driver/mongo" ) func newMongoStorDBMigrator(stor engine.StorDB) (mgoMig *mongoStorDBMigrator) { @@ -51,10 +51,12 @@ func (mgoMig *mongoStorDBMigrator) StorDB() engine.StorDB { //get func (v1ms *mongoStorDBMigrator) getV1CDR() (v1Cdr *v1Cdrs, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(engine.ColCDRs).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(engine.ColCDRs).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) @@ -94,10 +96,12 @@ func (v1ms *mongoStorDBMigrator) createV1SMCosts() (err error) { //get func (v1ms *mongoStorDBMigrator) getV2SMCost() (v2Cost *v2SessionsCost, err error) { if v1ms.cursor == nil { - v1ms.cursor, err = v1ms.mgoDB.DB().Collection(utils.SessionCostsTBL).Find(v1ms.mgoDB.GetContext(), bson.D{}) + var cursor mongo.Cursor + cursor, err = v1ms.mgoDB.DB().Collection(utils.SessionCostsTBL).Find(v1ms.mgoDB.GetContext(), bson.D{}) if err != nil { return nil, err } + v1ms.cursor = &cursor } if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { (*v1ms.cursor).Close(v1ms.mgoDB.GetContext())