diff --git a/dalmdl/coremongo/coremongo.go b/dalmdl/coremongo/coremongo.go index 8163d69b266d9e9ea8c7984ab0bfc06530ec87fa..4998e981a7f4feec598a213ebb1f698d00db6768 100644 --- a/dalmdl/coremongo/coremongo.go +++ b/dalmdl/coremongo/coremongo.go @@ -435,9 +435,40 @@ func (mg *MongoDAO) GetAggregateData(selector interface{}) (*gjson.Result, error return &rs, nil } +// UpsertWithID - will update or upsert a document in the collection +// +// If a new document is upserted then it will return the ObjectID (string) of the upserted document. +// +// If no document is upserted the object id returned will be empty string. +func (mg *MongoDAO) UpsertWithID(selector map[string]interface{}, data interface{}) (string, error) { + session, sessionError := GetMongoConnection(mg.hostName) + if errormdl.CheckErr(sessionError) != nil { + return "", errormdl.CheckErr(sessionError) + } + + if mg.hostName == "" { + mg.hostName = defaultHost + } + db, ok := config[mg.hostName] + if !ok { + return "", errormdl.Wrap("No_Configuration_Found_For_Host: " + mg.hostName) + } + collection := session.Database(db.Database).Collection(mg.collectionName) + ops := options.UpdateOptions{} + ops.SetUpsert(true) + upsertRes, updateError := collection.UpdateOne(context.Background(), selector, bson.M{"$set": data}, &ops) + if errormdl.CheckErr1(updateError) != nil { + return "", errormdl.CheckErr1(updateError) + } + if upsertRes.UpsertedID != nil { + return getInsertedId(upsertRes.UpsertedID), nil + } + return "", nil +} + // Upsert will update single entry func (mg *MongoDAO) Upsert(selector map[string]interface{}, data interface{}) error { - session, sessionError := GetMongoConnection(mg.hostName) + /* session, sessionError := GetMongoConnection(mg.hostName) if errormdl.CheckErr(sessionError) != nil { return errormdl.CheckErr(sessionError) } @@ -456,7 +487,9 @@ func (mg *MongoDAO) Upsert(selector map[string]interface{}, data interface{}) er if errormdl.CheckErr1(updateError) != nil { return errormdl.CheckErr1(updateError) } - return nil + return nil */ + _, err := mg.UpsertWithID(selector, data) + return err } // PushData - append in array diff --git a/grpcclientmdl/grpcclientmdl.go b/grpcclientmdl/grpcclientmdl.go index 75b3565c09f091176da8569ca3b8e860bcf3c42b..ae96cfff3d5312562c119091a7068b3955cc6116 100644 --- a/grpcclientmdl/grpcclientmdl.go +++ b/grpcclientmdl/grpcclientmdl.go @@ -65,7 +65,12 @@ func ByteHandler(req *grpcbuildermdl.GRPCRequest, grpcServerURL string) ([]byte, func CreateConnection(serverURL string, grpcClientName string) { var factory grpcpool.Factory factory = func() (*grpc.ClientConn, error) { - conn, err := grpc.Dial(serverURL, grpc.WithInsecure()) + maxMsgSize := 50 * 1024 * 1024 + conn, err := grpc.Dial( + serverURL, + grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize), grpc.MaxCallSendMsgSize(maxMsgSize)), + grpc.WithInsecure(), + ) if err != nil { loggermdl.LogError("Failed to start gRPC connection: %v", err) } diff --git a/routebuildermdl/grpcservermdl.go b/routebuildermdl/grpcservermdl.go index 247b579b4db4a2936224dac66483d6bd518ddc8e..7e16a4d6288a042dc1e90177e1f1eb88f908d4d3 100644 --- a/routebuildermdl/grpcservermdl.go +++ b/routebuildermdl/grpcservermdl.go @@ -21,7 +21,8 @@ type Server struct{} // GRPCInit init func GRPCInit(GRPCPort net.Listener) { loggermdl.LogInfo("In GRPCInit") - s := grpc.NewServer() + maxMsgSize := 50 * 1024 * 1024 + s := grpc.NewServer(grpc.MaxRecvMsgSize(maxMsgSize), grpc.MaxSendMsgSize(maxMsgSize)) grpcbuildermdl.RegisterGRPCCheckServer(s, &Server{}) grpcbuildermdl.RegisterGRPCServiceServer(s, &Server{}) if err := s.Serve(GRPCPort); err != nil {