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 (
|
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
|
|
|
}
|