devicemngmt/action_delete.go

32 lines
595 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"
)
2021-11-06 10:35:29 +00:00
// DeleteByDeviceID ...
func (s Service) DeleteByDeviceID(deviceID string) error {
2021-11-05 10:36:30 +00:00
var (
ctx = context.Background()
col = s.getDeviceCollection()
cond = bson.M{
2021-11-08 10:23:03 +00:00
"deviceId": deviceID,
2021-11-05 10:36:30 +00:00
}
)
// Delete
if _, err := col.DeleteOne(ctx, cond); err != nil {
2021-11-06 10:35:29 +00:00
logger.Error("devicemngt - deleteByDeviceID", logger.LogData{
2021-11-08 10:23:03 +00:00
"deviceId": deviceID,
2021-11-05 10:36:30 +00:00
"err": err.Error(),
})
return fmt.Errorf("error when delete device: %s", err.Error())
}
return nil
}