Release v1.2.1

Merged Akshay Bharambe requested to merge devbranch into staging
Compare and
3 files
+ 43
4
Preferences
File browser
Compare changes
@@ -435,9 +435,40 @@ func (mg *MongoDAO) GetAggregateData(selector interface{}) (*gjson.Result, error
return &rs, nil
}
// UpsertWithID - will update or upsert a document in the collection
//
// If a new document is upserted then it will return the ObjectID (string) of the upserted document.
//
// If no document is upserted the object id returned will be empty string.
func (mg *MongoDAO) UpsertWithID(selector map[string]interface{}, data interface{}) (string, error) {
session, sessionError := GetMongoConnection(mg.hostName)
if errormdl.CheckErr(sessionError) != nil {
return "", errormdl.CheckErr(sessionError)
}
if mg.hostName == "" {
mg.hostName = defaultHost
}
db, ok := config[mg.hostName]
if !ok {
return "", errormdl.Wrap("No_Configuration_Found_For_Host: " + mg.hostName)
}
collection := session.Database(db.Database).Collection(mg.collectionName)
ops := options.UpdateOptions{}
ops.SetUpsert(true)
upsertRes, updateError := collection.UpdateOne(context.Background(), selector, bson.M{"$set": data}, &ops)
if errormdl.CheckErr1(updateError) != nil {
return "", errormdl.CheckErr1(updateError)
}
if upsertRes.UpsertedID != nil {
return getInsertedId(upsertRes.UpsertedID), nil
}
return "", nil
}
// Upsert will update single entry
func (mg *MongoDAO) Upsert(selector map[string]interface{}, data interface{}) error {
session, sessionError := GetMongoConnection(mg.hostName)
/* session, sessionError := GetMongoConnection(mg.hostName)
if errormdl.CheckErr(sessionError) != nil {
return errormdl.CheckErr(sessionError)
}
@@ -456,7 +487,9 @@ func (mg *MongoDAO) Upsert(selector map[string]interface{}, data interface{}) er
if errormdl.CheckErr1(updateError) != nil {
return errormdl.CheckErr1(updateError)
}
return nil
return nil */
_, err := mg.UpsertWithID(selector, data)
return err
}
// PushData - append in array