devicemngmt/action_check_exists.go

27 lines
537 B
Go
Raw Permalink Normal View History

2021-11-22 09:02:55 +00:00
package devicemngmt
import (
"context"
2022-10-11 07:33:56 +00:00
"git.selly.red/Selly-Modules/logger"
2021-11-22 09:02:55 +00:00
"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 (
2021-11-23 05:57:22 +00:00
col = s.getDeviceCollection()
ctx = context.Background()
2021-11-22 09:02:55 +00:00
)
2021-11-23 05:57:22 +00:00
total, err := col.CountDocuments(ctx, bson.M{"deviceId": deviceID})
if err != nil {
logger.Error("devicemngmt - isDeviceIDExisted", logger.LogData{
2022-10-05 10:23:29 +00:00
Source: "devicemngmt.IsDeviceIDExisted",
Message: err.Error(),
Data: deviceID,
2021-11-22 09:02:55 +00:00
})
return true
}
2021-11-23 05:57:22 +00:00
return total != 0
2021-11-22 09:02:55 +00:00
}