devicemngmt/action_check_exists.go

26 lines
498 B
Go
Raw Normal View History

2021-11-22 09:02:55 +00:00
package devicemngmt
import (
"context"
2022-10-10 08:50:17 +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{
2021-11-22 09:02:55 +00:00
"deviceId": deviceID,
"err": err.Error(),
})
return true
}
2021-11-23 05:57:22 +00:00
return total != 0
2021-11-22 09:02:55 +00:00
}