From 4c89b56b0f4a7a9a68011b19cbc0c15563c2811c Mon Sep 17 00:00:00 2001 From: Chris kerr Date: Wed, 18 Sep 2024 20:00:14 -0400 Subject: [PATCH] change in parameterized replaceable handling --- server/db/mongo/kinds/replaceableParameters.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/server/db/mongo/kinds/replaceableParameters.go b/server/db/mongo/kinds/replaceableParameters.go index 2851094..f1ccd57 100644 --- a/server/db/mongo/kinds/replaceableParameters.go +++ b/server/db/mongo/kinds/replaceableParameters.go @@ -8,7 +8,6 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" "golang.org/x/net/websocket" ) @@ -48,18 +47,14 @@ func HandleParameterizedReplaceableKind(ctx context.Context, evt relay.Event, co fmt.Printf("Deleted older event with ID: %s\n", existingEvent.ID) } - // Step 6: Upsert the new event (insert if not existing, or update if newer) - opts := options.Update().SetUpsert(true) - update := bson.M{ - "$set": evt, - } - _, err = collection.UpdateOne(ctx, filter, update, opts) + // Step 6: Insert the new event (replaceable) + _, err = collection.InsertOne(ctx, evt) if err != nil { response.SendOK(ws, evt.ID, false, "error: could not connect to the database") - return fmt.Errorf("error updating/inserting event kind %d into MongoDB: %v", evt.Kind, err) + return fmt.Errorf("error inserting event kind %d into MongoDB: %v", evt.Kind, err) } - fmt.Printf("Upserted event kind %d into MongoDB: %s\n", evt.Kind, evt.ID) + fmt.Printf("Inserted event kind %d into MongoDB: %s\n", evt.Kind, evt.ID) response.SendOK(ws, evt.ID, true, "") return nil }