insert uuid
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package mongo
|
||||
|
||||
// func TestMongoInit(T *testing.T){
|
||||
// MongoInit()
|
||||
// fmt.Printf("It worked !")
|
||||
// }
|
||||
Reference in New Issue
Block a user