insert uuid

This commit is contained in:
mr
2024-07-22 14:02:48 +02:00
parent f7dfbe91dd
commit 9f17532646
3 changed files with 7 additions and 17 deletions

View File

@@ -2,7 +2,6 @@ package mongo
import (
"context"
"encoding/json"
"errors"
"time"
@@ -161,14 +160,11 @@ func (m *MongoDB) UpdateOne(set map[string]interface{}, id string, collection_na
return result.UpsertedID.(primitive.ObjectID).Hex(), 200, nil
}
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.UnmarshalExtJSON(b, false, &doc)
func (m *MongoDB) StoreOne(obj interface{}, id string, collection_name string) (string, int, error) {
var doc map[string]interface{}
b, _ := bson.Marshal(obj)
bson.Unmarshal(b, &doc)
doc["_id"] = id
targetDBCollection := CollectionMap[collection_name]
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)

View File

@@ -1,6 +0,0 @@
package mongo
// func TestMongoInit(T *testing.T){
// MongoInit()
// fmt.Printf("It worked !")
// }