Skip to content

Commit

Permalink
change in parameterized replaceable handling
Browse files Browse the repository at this point in the history
  • Loading branch information
0ceanSlim committed Sep 19, 2024
1 parent 63a0daa commit 4c89b56
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions server/db/mongo/kinds/replaceableParameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

0 comments on commit 4c89b56

Please sign in to comment.