{"record":{"id":"a705d2efa451f6f9","repo":"elsa-workflows/elsa-core","slug":"mongodb-physicalization-supports-dedicated-document","errorCode":null,"errorMessage":"MongoDB physicalization supports dedicated document collections only.","messagePattern":"MongoDB physicalization supports dedicated document collections only\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Persistence.VNext.MongoDb/Physicalization/MongoDbPhysicalizationPlanner.cs","lineNumber":11,"sourceCode":"using Elsa.Persistence.VNext;\nusing Elsa.Persistence.VNext.Physicalization;\n\nnamespace Elsa.Persistence.VNext.MongoDb.Physicalization;\n\npublic class MongoDbPhysicalizationPlanner : IPhysicalizationPlanner\n{\n    public PhysicalizationPlan Plan(PersistenceSchema schema, StoragePhysicalizationPolicy policy)\n    {\n        if (policy.Target != PhysicalizationTarget.DedicatedDocumentCollection)\n            throw new InvalidOperationException(\"MongoDB physicalization supports dedicated document collections only.\");\n\n        PhysicalizationPolicyValidator.GetStorageUnit(schema, policy);\n\n        var collectionName = NormalizeName(policy.PhysicalName ?? policy.StorageUnit);\n        var operations = new List<PhysicalizationOperation>\n        {\n            new(\"CreateCollection\", $\"Create dedicated MongoDB collection {collectionName} for {policy.StorageUnit}.\")\n        };\n\n        foreach (var index in policy.Indexes)\n        {\n            var fields = string.Join(\",\", index.Fields.Select(field => $\"Data.{field}:1\"));\n            var uniqueness = index.IsUnique ? \"unique\" : \"non-unique\";\n            operations.Add(new(\n                \"CreateIndex\",\n                $\"Create {uniqueness} MongoDB index {index.Name} on {collectionName} ({fields}).\"));\n        }\n","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Persistence.VNext.MongoDb/Physicalization/MongoDbPhysicalizationPlanner.cs#L1-L29","documentation":"MongoDbPhysicalizationPlanner.Plan maps a persistence schema to MongoDB physical objects, but it only implements the DedicatedDocumentCollection strategy where each storage unit becomes its own collection. Passing any other PhysicalizationTarget throws InvalidOperationException during planning.","triggerScenarios":"Calling Plan with a StoragePhysicalizationPolicy whose Target is anything other than PhysicalizationTarget.DedicatedDocumentCollection (e.g. a shared-table or embedded strategy).","commonSituations":"Configuring the physicalization policy copied from a relational-provider setup; a shared policy object defaulting to a non-Mongo target; switching persistence providers without updating the target enum.","solutions":["Set policy.Target = PhysicalizationTarget.DedicatedDocumentCollection in your StoragePhysicalizationPolicy when using the MongoDB provider.","If another target is required, use the persistence provider that implements it instead of the MongoDB planner.","Centralize policy construction per provider so the relational and MongoDB configurations are not shared."],"exampleFix":"// before\nvar policy = new StoragePhysicalizationPolicy { StorageUnit = \"orders\", Target = PhysicalizationTarget.SharedTable };\nvar plan = planner.Plan(schema, policy); // throws\n\n// after\nvar policy = new StoragePhysicalizationPolicy { StorageUnit = \"orders\", Target = PhysicalizationTarget.DedicatedDocumentCollection };\nvar plan = planner.Plan(schema, policy);","handlingStrategy":"type-guard","validationCode":"if (policy.Target != PhysicalizationTarget.DedicatedDocumentCollection)\n    throw new NotSupportedException($\"MongoDB provider only supports DedicatedDocumentCollection, got {policy.Target}.\");","typeGuard":"static bool IsMongoCompatible(StoragePhysicalizationPolicy p) => p.Target == PhysicalizationTarget.DedicatedDocumentCollection;","tryCatchPattern":"try\n{\n    var plan = planner.Plan(schema, policy);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"physicalization\"))\n{\n    logger.LogError(ex, \"Incompatible physicalization target {Target}\", policy.Target);\n    throw;\n}","preventionTips":["Configure PhysicalizationTarget per persistence provider; do not share policy objects between relational and MongoDB setups.","Only ever set PhysicalizationTarget.DedicatedDocumentCollection when using the MongoDB provider.","Assert the target in startup configuration tests so misconfiguration fails fast."],"tags":["mongodb","physicalization","unsupported-target","configuration"],"backgroundTag":"unsupported-enum-value","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}