update set
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user