diff --git a/db/mongo.go b/db/mongo.go index 414e844..feeb198 100644 --- a/db/mongo.go +++ b/db/mongo.go @@ -166,6 +166,19 @@ func (c *mongoCollection) DeleteOne(ctx context.Context, key interface{}) error return nil } +// Delete Many entries matching the delete criteria +// returns number of entries deleted and if there is any error processing the request +func (c *mongoCollection) DeleteMany(ctx context.Context, filter interface{}) (int64, error) { + resp, err := c.col.DeleteMany(ctx, filter) + if err != nil { + return 0, err + } + if resp.DeletedCount == 0 { + return 0, errors.Wrap(errors.NotFound, "No matching entries found to delete") + } + return resp.DeletedCount, nil +} + // watch allows getting notified whenever a change happens to a document // in the collection func (c *mongoCollection) Watch(ctx context.Context, cb WatchCallbackfn) error { diff --git a/db/store.go b/db/store.go index 01b2dbc..ea16fb3 100644 --- a/db/store.go +++ b/db/store.go @@ -44,6 +44,10 @@ type StoreCollection interface { // remove one entry from the collection matching the given key DeleteOne(ctx context.Context, key interface{}) error + // Delete Many entries matching the delete criteria + // returns number of entries deleted and if there is any error processing the request + DeleteMany(ctx context.Context, filter interface{}) (int64, error) + // watch allows getting notified whenever a change happens to a document // in the collection Watch(ctx context.Context, cb WatchCallbackfn) error