From bff00bfa84492d015a6f985e41df58386105115e Mon Sep 17 00:00:00 2001 From: Hoang Date: Wed, 24 Nov 2021 15:36:24 +0700 Subject: [PATCH] add deleteByUserID --- action_delete.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/action_delete.go b/action_delete.go index 4721d45..0c970ac 100644 --- a/action_delete.go +++ b/action_delete.go @@ -35,3 +35,25 @@ func (s Service) DeleteByDeviceID(deviceID string) error { return nil } + +// DeleteByUserID ... +func (s Service) DeleteByUserID(userID string) error { + var ( + ctx = context.Background() + col = s.getDeviceCollection() + cond = bson.M{ + "userId": userID, + } + ) + + // Delete + if _, err := col.DeleteMany(ctx, cond); err != nil { + logger.Error("devicemngmt - deleteByUserID", logger.LogData{ + "userId": userID, + "err": err.Error(), + }) + return fmt.Errorf("error when delete device by userId: %s", err.Error()) + } + + return nil +}