From 1c4cbb18686bf734843ec710d53f8c69894740f4 Mon Sep 17 00:00:00 2001 From: Hoang Date: Tue, 23 Nov 2021 12:57:22 +0700 Subject: [PATCH] update IsDeviceIDExisted --- action_check_exists.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/action_check_exists.go b/action_check_exists.go index bc807f5..8eeb6a1 100644 --- a/action_check_exists.go +++ b/action_check_exists.go @@ -9,17 +9,17 @@ import ( func (s Service) IsDeviceIDExisted(deviceID string) bool { var ( - col = s.getDeviceCollection() - device = Device{} - ctx = context.Background() + col = s.getDeviceCollection() + ctx = context.Background() ) - if err := col.FindOne(ctx, bson.M{"deviceId": deviceID}).Decode(&device); err != nil { - logger.Error("devicemngmt - findByDeviceID", logger.LogData{ + total, err := col.CountDocuments(ctx, bson.M{"deviceId": deviceID}) + if err != nil { + logger.Error("devicemngmt - isDeviceIDExisted", logger.LogData{ "deviceId": deviceID, "err": err.Error(), }) return true } - return !device.ID.IsZero() + return total != 0 }