From 403944b249b1e8b30205f08140903d2a72763e2a Mon Sep 17 00:00:00 2001 From: hz Date: Thu, 23 Jul 2026 13:40:53 -0500 Subject: [PATCH] Assign IDs when promoting dynamic blueprints --- api/QuestionsApi/Services/DynamicQuestionStore.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/QuestionsApi/Services/DynamicQuestionStore.cs b/api/QuestionsApi/Services/DynamicQuestionStore.cs index 3c591c7..ff5ecec 100644 --- a/api/QuestionsApi/Services/DynamicQuestionStore.cs +++ b/api/QuestionsApi/Services/DynamicQuestionStore.cs @@ -1,4 +1,5 @@ using MongoDB.Driver; +using MongoDB.Bson; using QuestionsApi.Models; namespace QuestionsApi.Services; @@ -116,9 +117,15 @@ public sealed class DynamicQuestionStore public async Task UpsertBlueprintsAsync(IEnumerable blueprints) { foreach (var blueprint in blueprints) + { + var existing = await _blueprints.Find( + value => value.ExternalId == blueprint.ExternalId && value.Version == blueprint.Version) + .FirstOrDefaultAsync(); + blueprint.Id = existing is null ? ObjectId.GenerateNewId().ToString() : existing.Id; await _blueprints.ReplaceOneAsync( value => value.ExternalId == blueprint.ExternalId && value.Version == blueprint.Version, blueprint, new ReplaceOptions { IsUpsert = true }); + } } }