// AddServiceToGroup add service to an existing service group
AddServiceToGroup add service to an existing service group
// AddServiceToGroup add service to an existing service group
func (sgmr *ServiceGroupMongoRepository) AddServiceToGroup(serviceGroupID string, serviceID string) error {
	serviceGroupIdHex := bson.ObjectIdHex(serviceGroupID)
	serviceIdHex := bson.ObjectIdHex(serviceID)
	removeFromAllGroups := bson.M{"$pull": bson.M{"services": serviceIdHex}}
	updateGroup := bson.M{"$addToSet": bson.M{"services": serviceIdHex}}
	updateService := bson.M{"$set": bson.M{"groupid": serviceGroupIdHex}}
	err := sgmr.Db.C(constants.SERVICES_COLLECTION).UpdateId(serviceIdHex, updateService)
	if err != nil {
		return errors.New("Update Service failed")
	}
	_, err = sgmr.Collection.UpdateAll(bson.M{}, removeFromAllGroups)
	if err != nil {
		return errors.New("Update Service failed")
	}
	return sgmr.Collection.UpdateId(serviceGroupIdHex, updateGroup)
}
func ( sgmr * ServiceGroupMongoRepository ) AddServiceToGroup ( serviceGroupID string , serviceID string ) error { serviceGroupIdHex := bson . ObjectIdHex ( serviceGroupID ) serviceIdHex := bson . ObjectIdHex ( serviceID ) removeFromAllGroups := bson . M { " " : bson . M { " " : serviceIdHex } } updateGroup := bson . M { " " : bson . M { " " : serviceIdHex } } updateService := bson . M { " " : bson . M { " " : serviceGroupIdHex } } err := sgmr . Db . C ( constants . SERVICES_COLLECTION ) . UpdateId ( serviceIdHex , updateService ) if err != nil { return errors . New ( " " ) } _ , err = sgmr . Collection . UpdateAll ( bson . M { } , removeFromAllGroups ) if err != nil { return errors . New ( " " ) } return sgmr . Collection . UpdateId ( serviceGroupIdHex , updateGroup ) }
AddServiceToGroup add service to an existing service group
AddServiceToGroup add service to an existing service group