update set

This commit is contained in:
mr
2024-07-22 16:12:38 +02:00
parent 4a90d3379c
commit ebdbd97ce6
10 changed files with 14 additions and 11 deletions

View File

@@ -145,13 +145,16 @@ func (m *MongoDB) DeleteOne(id string, collection_name string) (int64, int, erro
return result.DeletedCount, 200, nil
}
func (m *MongoDB) UpdateOne(set map[string]interface{}, id string, collection_name string) (string, int, error) {
func (m *MongoDB) UpdateOne(set interface{}, id string, collection_name string) (string, int, error) {
var doc map[string]interface{}
b, _ := bson.Marshal(set)
bson.Unmarshal(b, &doc)
filter := bson.M{"_id": id}
targetDBCollection := CollectionMap[collection_name]
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := targetDBCollection.UpdateOne(MngoCtx, filter, dbs.InputToBson(set, true))
_, err := targetDBCollection.UpdateOne(MngoCtx, filter, dbs.InputToBson(doc, true))
if err != nil {
m.Logger.Error().Msg("Couldn't update resource: " + err.Error())
return "", 404, err