Execution
This commit is contained in:
@@ -146,6 +146,24 @@ func (m *MongoDB) DeleteOne(id string, collection_name string) (int64, int, erro
|
||||
return result.DeletedCount, 200, nil
|
||||
}
|
||||
|
||||
func (m *MongoDB) DeleteMultiple(f map[string]interface{}, collection_name string) (int64, int, error) {
|
||||
filter := bson.D{}
|
||||
for k, v := range f {
|
||||
filter = append(filter, bson.E{Key: k, Value: v})
|
||||
}
|
||||
targetDBCollection := CollectionMap[collection_name]
|
||||
opts := options.Delete().SetHint(bson.D{{Key: "_id", Value: 1}})
|
||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
result, err := targetDBCollection.DeleteMany(MngoCtx, filter, opts)
|
||||
if err != nil {
|
||||
m.Logger.Error().Msg("Couldn't insert resource: " + err.Error())
|
||||
return 0, 404, err
|
||||
}
|
||||
return result.DeletedCount, 200, nil
|
||||
}
|
||||
|
||||
func (m *MongoDB) UpdateOne(set interface{}, id string, collection_name string) (string, int, error) {
|
||||
var doc map[string]interface{}
|
||||
b, _ := bson.Marshal(set)
|
||||
|
Reference in New Issue
Block a user