Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions db/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions db/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down