devicemngmt/action_check_exists.go

25 lines
518 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"
)
func (s Service) IsDeviceIDExisted(ctx context.Context, deviceID string) bool {
var (
col = s.getDeviceCollection()
device = Device{}
)
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()
}