devicemngmt/action_delete.go

32 lines
613 B
Go
Raw Normal View History

2021-11-05 10:36:30 +00:00
package devicemngmt
import (
"context"
"fmt"
"github.com/Selly-Modules/logger"
"go.mongodb.org/mongo-driver/bson"
)
// DeleteDeviceByDeviceID ...
func (s Service) DeleteDeviceByDeviceID(deviceID string) error {
var (
ctx = context.Background()
col = s.getDeviceCollection()
cond = bson.M{
"deviceID": deviceID,
}
)
// Delete
if _, err := col.DeleteOne(ctx, cond); err != nil {
logger.Error("devicemngt - deleteDeviceByDeviceID", logger.LogData{
"deviceID": deviceID,
"err": err.Error(),
})
return fmt.Errorf("error when delete device: %s", err.Error())
}
return nil
}