devicemngmt/action_check_exists.go

26 lines
529 B
Go
Raw Normal View History

2021-11-22 09:02:55 +00:00
package devicemngmt
import (
"context"
"github.com/Selly-Modules/logger"
"go.mongodb.org/mongo-driver/bson"
)
2021-11-22 09:05:28 +00:00
func (s Service) IsDeviceIDExisted(deviceID string) bool {
2021-11-22 09:02:55 +00:00
var (
col = s.getDeviceCollection()
device = Device{}
2021-11-22 09:05:28 +00:00
ctx = context.Background()
2021-11-22 09:02:55 +00:00
)
if err := col.FindOne(ctx, bson.M{"deviceId": deviceID}).Decode(&device); err != nil {
logger.Error("devicemngmt - findByDeviceID", logger.LogData{
"deviceId": deviceID,
"err": err.Error(),
})
return true
}
return !device.ID.IsZero()
}