test
This commit is contained in:
parent
6696b0faac
commit
b1293af229
@ -2,6 +2,7 @@ package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
@ -161,12 +162,19 @@ func (m *MongoDB) UpdateOne(set map[string]interface{}, id string, collection_na
|
||||
}
|
||||
|
||||
func (m *MongoDB) StoreOne(obj interface{}, collection_name string) (string, int, error) {
|
||||
var doc interface{}
|
||||
b, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
m.Logger.Error().Msg("Couldn't insert resource: " + err.Error())
|
||||
return "", 422, err
|
||||
}
|
||||
bson.Unmarshal(b, &doc)
|
||||
targetDBCollection := CollectionMap[collection_name]
|
||||
|
||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
result, err := targetDBCollection.InsertOne(MngoCtx, obj)
|
||||
result, err := targetDBCollection.InsertOne(MngoCtx, doc)
|
||||
if err != nil {
|
||||
m.Logger.Error().Msg("Couldn't insert resource: " + err.Error())
|
||||
return "", 409, err
|
||||
|
Loading…
Reference in New Issue
Block a user